我正在尝试将 json 对象传递给 angular 指令,但还找不到任何解决方案。
这是代码。
指令
function agEcalendar() {
var directive = {
restrict: 'E',
templateUrl: 'app/components/ecalendar/ecalendar.html',
scope: {
event: '@event'
},
controller: EcalendarController,
controllerAs: 'vm',
bindToController: true
};
return directive;
}
我在这里调用jade中的指令
ag-ecalendar(event='{{vm.calendar.event}}')
最佳答案
使用 <
传递对象(新的单向绑定(bind)选项)这将使您能够将对象传递给指令隔离范围。
scope: {
event: '<event'
},
HTML
ag-ecalendar(event='vm.calendar.event')
在当前情况下,它通过 @
传递只不过是将对象值转换为 string
.
Note The suggested way would work for Angular 1.5+ version, otherwise you need to make it as
event: '=event'
(eventually that will enable two way binding)
关于javascript - 将 JSON 对象传递给 Angular Directive(指令),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37302638/