gpt4 book ai didi

javascript - Angular 1.5 组件方法 templateUrl + function

转载 作者:行者123 更新时间:2023-12-03 01:22:26 25 4
gpt4 key购买 nike

我正在尝试让应用程序使用 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$attrs 的函数,但是如何将其与 templateUrl 结合起来?

最佳答案

在 1.5.0-beta.2 中 templateUrl 可以是由注入(inject)器调用的函数。 $element$attrs are injected进入both template and templateUrl functions组件中,以及任何其他依赖项。

这意味着

  ...
templateUrl: function ($element, $attrs) {
// access to $element and $attrs
...
return $attrs.uninterpolatedTemplateUrl;
}

可以替代。

关于javascript - Angular 1.5 组件方法 templateUrl + function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33841909/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com