如何访问控制器中的隔离范围?

时间:2017-02-21 01:20:11

标签: angularjs

我正在使用Angular 1.6。

如何从指令中获取隔离范围的权限?让我们说我想从我的隔离范围输出一些值,并在打印出来之前在字符串中添加一些额外的文本。

(function() {
  'use strict';

  angular.module('appStore', []);

  angular.module('appStore', [])
    .directive('productTitle', function nw($scope){
      return {
        restrict : 'E',
        templateUrl : 'product-title.html',
        scope : {
          namer : '='   // i'm passing a string in here.
        },
        link : function(scope, elem){
          scope.namer = scope.namer + ' additional text';  // when output, i get undefined + additional text.
        },
        controller : function($scope){
          $scope.namer = "test";  // this cause injection error
        }
      };
    });

}());

0 个答案:

没有答案