AngularJS ng-repeat with custom element inside a table is rendering strangely

前端 未结 3 1205
不知归路
不知归路 2020-12-08 04:58

I\'m trying to re-use a portion of my HTML view in multiple places. The portion I want to re-use is table cells in an HTML table. The problem is that my custom directive i

3条回答
  •  囚心锁ツ
    2020-12-08 05:22

    is known to behave strangely in directives like this. Instead, use a directive on the parent . Read more about this issue here: https://github.com/angular/angular.js/issues/1459

    Here is how you can further improve your directive so that it is more re-usable.

    app.directive('myElement', function () {
      return {
        scope: {
          item: '=myElement'
        },
        restrict: 'EA',
        template: 'Name: {{item.name}}Age: {{item.age}}'
        };
    });
    

    and pass in the value of item like so:

      

    Live Demo

提交回复
热议问题