【发布时间】:2017-07-06 21:36:36
【问题描述】:
我希望能够实现类似于以下的功能:
HTML
<mydir> {{config = {type: 'X', options: 'y'}} </mydir>
<mydir> {{config = {type: 'a', options: 'b'}} </mydir>
JS 指令
angular
.module('mymod', ['dependency'])
.controller('myCtrl', function($scope){
this.config = config;
this.type = config.type;
this.options = config.options
});
.directive('mydir', function($compile, $window){
return{
... code
template:
`<textarea type=this.type options=this.options> </textarea>
}
});
目标是能够将各种配置传递给控制器,并让指令处理模板。这样我就可以通过任何配置组合,并且指令应该处理它。
不确定是否有可能在 Angular 中实现这一点,因为我刚开始接触它,但希望它不会太复杂。
【问题讨论】:
标签: html angularjs angularjs-directive angularjs-controller