SoFunction
Updated on 2025-04-13

AngularJS method to implement custom instructions and controller data interaction

This article describes the method of AngularJS to interact with custom instructions and controller data. Share it for your reference, as follows:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>AngularJSCustom instructions interact with controller data</title>
<!--    <script src="//1.3.15/"></script>-->
    <script src="../../lib/angular/"></script>
    <script>
    ('yyApp', [])
    .controller('yyHelloController', function($scope){
      $ = {
        name: 'Zhang San'
      }
    })
    .controller('yyHelloController2', function($scope){
      $ = {
        name: 'Li Si'
      }
    })
    .directive('yyHello', function(){
      return{
        restrict: 'AE',
        replace: true,
        template: '<div name="{{}}">Hello,{{}}</div>'
      };
    });
    </script>
  </head>
  <body ng-app='yyApp'>
    <yy-hello ng-controller='yyHelloController'></yy-hello>
    <div ng-controller='yyHelloController2'>
      <input type="text" ng-model=''>
      <yy-hello></yy-hello>
    </div>
  </body>
</html>

For more information about AngularJS, readers who are interested in view the topic of this site:Summary of AngularJS command operation skills》、《AngularJS Introduction and Advanced Tutorial"and"AngularJS MVC architecture summary

I hope this article will be helpful to everyone's AngularJS programming.