我的指令有一个控制器,我试图弄清楚如何从传入的指令中传递一个值。在下面的例子中,'name'无效发布到控制台,但它在呈现时显示在html中。显然我的例子是过于简单化,但你明白了。如何将角度值传递给指令控制器?
angular.module('myApp')
.directive('helpLabel', function() {
return {
restrict: 'E',
scope: {
name: '@',
},
template: '<span>{{name}}</span>',
controller: function ($scope) {
console.log(name);
}
};
});
<helpLabel name="test"></helpLabel>