重新编辑
各位请看:link中我可以输出scope.type
可是在templateURL中scope.type为undefined
有点不懂directive的scope了,请各位指教谢谢
重新编辑
各位请看:link中我可以输出scope.type
可是在templateURL中scope.type为undefined
有点不懂directive的scope了,请各位指教谢谢
templateUrl执行还在compile之前,从哪里去注入的scope?
templateUrl的参数只有element,attrs。
如果你的type是静态的,可以这样用
<my-dir type="template.html"></my-dir>
.directive('myDir', function () {
return {
scope: {
type: '@'
},
templateUrl: function (element, attrs) {
return attrs.type;
}
}
});
13 回答12.8k 阅读
7 回答2k 阅读
3 回答1.1k 阅读✓ 已解决
2 回答1.2k 阅读✓ 已解决
6 回答929 阅读✓ 已解决
6 回答1.1k 阅读
2 回答1.3k 阅读✓ 已解决
templateURL function 只有2个参数
elem
和attr
哦。不能访问scope
,因为模版请求是在scope
初始化之前。可以通过属性传输,然后获取
return 'customer-'+attr.type+'.html'
,或者