AngularJS - Scope value not accessible in the directive Scope

前端 未结 6 1467
梦谈多话
梦谈多话 2021-01-26 09:01

FIDDLE

I have created a directive :-

return {
        restrict: \'EAC\',
        scope: {
            statesActive: \'=\'
        },            
                 


        
6条回答
  •  迷失自我
    2021-01-26 09:42

    inject $parse in your directive.... try this...

     angular.module('myApp').directive('gtMap', ['$parse',
        function($parse) {
          return {
              restrict: 'EAC',
    
              link: function (scope, element, attrs) {
                  var fieldGetter = $parse(attrs.statesActive);
                  console.log(fieldGetter)
                    var field = fieldGetter(scope);
                  //var stateData = scope.statesActive.states;
                  // Don't get data here
                  console.log(field)
              }
           }
        }
      ]);
    

提交回复
热议问题