我正在尝试让应用程序与 Angular 1.5.0-beta.2 一起使用
为了制定“指令”,我有以下代码:
myApp.component('gridshow', {
bindings: {
slides: '='
},
controller: function() {
},
controllerAs: 'grid',
template: function ($element, $attrs) {
// access to $element and $attrs
return [
'<div class="slidegrid">',
'<div ng-repeat="slide in grid.slides">',
'{{slide.image}}',
'</div>',
'</div>'
].join('')
}
});
我喜欢模板的想法,它返回一个可以访问的函数$element
and $attrs
但如何将其与 templateUrl 结合起来?
在 1.5.0-beta.2 中templateUrl
可以是由注入器调用的函数。$element
and $attrs
被注射 https://github.com/angular/angular.js/blob/v1.5.0-beta.2/src/loader.js#L366 into both template and templateUrl功能 https://github.com/angular/angular.js/blob/v1.5.0-beta.2/src/loader.js#L378 in component
,以及任何其他依赖项。
这意味着
...
templateUrl: function ($element, $attrs) {
// access to $element and $attrs
...
return $attrs.uninterpolatedTemplateUrl;
}
可以代替。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)