[英]Pass bindings to TemplateUrl in Angular's component
My component object looks like this: 我的组件对象如下所示:
var options = {
bindings: {
title: '<',
rows: '<'
},
controller: registers,
templateUrl: function ($element, $attrs) {
return '/app/dashboard/registers/register.html';
}
};
I need access to the bindings title
and rows
in my register.html
markup. 我需要访问
register.html
标记中的绑定title
和rows
。 I understand $element
and $attrs
but I'm not quite sure how to inject that into a templateUrl which is a string reference to an HTML file. 我理解
$element
和$attrs
但我不太确定如何将它注入到templateUrl中,这是对HTML文件的字符串引用。
I would like to be able to use those values in the template as such: 我希望能够在模板中使用这些值:
<p>Title: {{vm.title}}</p>
<p>Rows: {{vm.rows}}</p>
Can someone point me in a direction where the templateUrl can use the curly braces to embed the values of the bindings into the markup? 有人能指出我的方向,templateUrl可以使用花括号将绑定的值嵌入到标记中吗?
It isn't related to templateUrl
function, no extra actions should be performed there. 它与
templateUrl
函数无关,不应在那里执行额外的操作。
If no controllerAs
option is specified, controller identifier defaults to $ctrl
, not vm
. 如果未指定
controllerAs
选项,则控制器标识符默认为$ctrl
,而不是vm
。 Scope properties should be available in template as 范围属性应在模板中可用
<p>Title: {{$ctrl.title}}</p>
<p>Rows: {{$ctrl.rows}}</p>
Here is a demo that shows this (thanks to @AWolf). 这是一个展示这个的演示 (感谢@AWolf)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.