有没有办法将a传递templateUrl
给我的指令.我知道我可以使用翻译,但这似乎太多了.例如,我有一个widget
指令,我想填写特定的HTML.有没有办法传递它像:
<div widget templateUrl="template1.html"></div>
<div widget templateUrl="template2.html"></div>
Run Code Online (Sandbox Code Playgroud) 我的组件对象如下所示:
var options = {
bindings: {
title: '<',
rows: '<'
},
controller: registers,
templateUrl: function ($element, $attrs) {
return '/app/dashboard/registers/register.html';
}
};
Run Code Online (Sandbox Code Playgroud)
我需要访问绑定title
和rows
我的register.html
标记.我理解$element
,$attrs
但我不太确定如何将其注入到templateUrl中,这是一个HTML文件的字符串引用.
我希望能够在模板中使用这些值:
<p>Title: {{vm.title}}</p>
<p>Rows: {{vm.rows}}</p>
Run Code Online (Sandbox Code Playgroud)
有人能指出我的方向,templateUrl可以使用花括号将绑定的值嵌入到标记中吗?
我正在尝试创建一个自定义角度组件,该组件基于 templateUrl 函数动态加载模板。我目前得到一个templateUrl
未使用显式注释并且无法在严格模式下调用的错误。通常我知道当注入的服务没有得到正确注释时会出现这个错误(https://docs.angularjs.org/error/$injector/strictdi)。但是,我缺少这如何适用于templateUrl
.
我正在使用 Angular 1.5。
确切的错误信息是 -
angular.js:13550 Error: [$injector:strictdi] templateUrl is not using explicit annotation and cannot be invoked in strict mode
组件代码片段:
angular.module('hive.triGrid')
.controller('TriGridCellController', ['$element', '$attrs', function ($element, $attrs) {
var $ctrl = this;
}])
.component('triGridCell', {
controller: 'TriGridCellController',
templateUrl: function($element, $attrs)
{
var type = $attrs.cellType;
if(type.toUpperCase() == "ICON")
{
return "components/grid/cellTemplates/iconCell.tpl.html";
}
else if(type.toUpperCase() == "CUSTOM")
{
return $attrs.cellTemplateUrl;
}
else
{
return "components/grid/cellTemplates/textCell.tpl.html";
}
},
//template:"<ng-include src='$ctrl.getTemplateUrl(z)'/>",
bindings: …
Run Code Online (Sandbox Code Playgroud)