我们可以将scope参数传递给指令
app.directive('appInfo', function() {
return {
restrict: 'E',
scope: {
info: '='
},
templateUrl: 'js/directives/appInfo.html'
};
});
并在视图中使用如下:
<app-info info="app"></app-info>
组件也可以用作指令:
<component-info></component-info>
但是我们可以传递一个与 info =“app”相同的范围参数吗?
答案 0 :(得分:2)
是的,对于组件,您将使用bindings
而不是范围。所以你的组件定义看起来会像这样:
app.component('componentInfo', {
bindings: {
info: '='
},
// ... and so on
});