AngularJS directive scope not resolved (“attr name is not defined” error)

前端 未结 2 1617
萌比男神i
萌比男神i 2020-12-21 19:22

Directive code

mymodule.directive(\'eicon\', function(){
    return {
        restrict: \'E\',
        scope: {
            attr: \'=\'
        },
        te         


        
2条回答
  •  长情又很酷
    2020-12-21 19:45

    Since you are declaring isolated scope property attr you should be able to access scope.attr in template like this:

    mymodule.directive('eicon', function(){
        return {
            restrict: 'E',
            scope: {
                attr: '='
            },
            template: "test {{attr.name}}"
        }
    });
    

    Demo: http://plnkr.co/edit/YZ0aPqhkMlIIwmrkKK2v?p=preview

提交回复
热议问题