【问题标题】:AngularJS valuesAngularJS 价值观
【发布时间】:2017-04-25 19:46:37
【问题描述】:

如何在我的指令中获取 FirstName 值?

<hello-World value="{{item.FirstName}}"> </hello-World>
app.directive('helloWorld', function() {
return {
  restrict: 'AE',
  replace: 'true',
  template: '<h3>Hello ??????</h3>'
 }; 
});

【问题讨论】:

    标签: angularjs angularjs-directive


    【解决方案1】:

    要获取值,您需要在指令中使用scope 参数。在此处阅读更多指令https://docs.angularjs.org/guide/directive

    检查这个例子

    angular.module('myApp', [])
    .directive('helloWorld', function() {
    return {
      restrict: 'AE',
      replace: 'true',
      template: '<h3>Hello {{value}}</h3>',
      scope: {
          value: '@'
        },
     }; 
    });
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <div ng-app="myApp">
    
    <hello-World value='World' />
    
    </div>

    【讨论】:

      【解决方案2】:
      app.directive('helloWorld', function() {
      return {
        restrict: 'AE',
        replace: 'true',
        template: '<h3>Hello {{value}}</h3>',
        scope: {
           value: '='
        }
       }; 
      });
      

      【讨论】:

        猜你喜欢
        • 2022-11-21
        • 2015-12-25
        • 1970-01-01
        • 2017-11-18
        • 1970-01-01
        • 1970-01-01
        • 2020-03-08
        • 2019-10-29
        • 1970-01-01
        相关资源
        最近更新 更多