简体   繁体   中英

i have included same directive in 2 html file

Hello I have included the directive in 2 html files. app is ng-app.

<dir auto=""></div>

code in a directive

app.directive("auto", function() {
  scope: {
    arr : "="
  },
  templateUrl : "myHtml.hmtl",
  restrict : 'EAC',
  link : function(element,scope,attrs) {
    scope.getData = function() {
      //here data is store in arr variable
    };
    scope.getData();
  }
});

now in myHtml.html file i have used the arr. i have used ng-repeat in myHtml.html file. For ng-repeat i have used arr.

My problem is in one file i am able to get the data in myHtml.html file. but in another html file i have used the same directive but i am not able to get the data.

sorry I am not having a much time to make a jsFiddle or plunker for the same.

Are you passing in the arr to the directive in both instances? It doesn't look like it from the code you posted, the correct way to use that directive would be:

<div auto arr="myArr"></div>

and your parent controllers $scope :

$scope.myArr=[1,2,3,4,5....];

Also there are multiple typos there, myHtml.ht* l *m , also link : function(element,scope,attrs){ won't work correctly, since teh order of parameters matters, it should be: link : function(scope,element,attrs){ instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM