Angular Directive Does Not Evaluate Inside ng-repeat

后端 未结 6 1718
予麋鹿
予麋鹿 2020-12-30 08:38

I have the following setup:

App/Directive

var app = angular.module(\"MyApp\", []);

app.directive(\"adminRosterItem\", function () {
    return {
            


        
6条回答
  •  长发绾君心
    2020-12-30 09:28

    i think the right way to approach this would be to send the object into admin roster item, like this:

    
               
      
    
    

    and in the directive:

    var app = angular.module("MyApp", []);
    
    app.directive("adminRosterItem", function () {
      return {
        restrict: "E",
        scope: {
            pos: "@"
        },
        template: "{{ formattedText }}", // should I have this?
        link: function(scope, element, attrs){
            // all of this can easily be done with a filter, but i understand you just want to     
            // know how it works
            scope.formattedText = scope.pos.Name + ' (' + scope.pos.Code + ')';
        }
      }
    });
    

    PS. i didn't test this!

提交回复
热议问题