扫码关注官方订阅号
重新编辑
各位请看:link中我可以输出scope.type可是在templateURL中scope.type为undefined有点不懂directive的scope了,请各位指教谢谢
光阴似箭催人老,日月如移越少年。
templateURL function 只有2个参数 elem 和 attr哦。不能访问scope,因为模版请求是在scope初始化之前。
elem
attr
scope
可以通过属性传输,然后获取return 'customer-'+attr.type+'.html',或者
return 'customer-'+attr.type+'.html'
... link: function(scope) { scope.customerUrl = 'customer-'+scope.type+'.html' }, template: '<p ng-include="customerUrl"></p>' ...
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; } } });
你有什么问题?
把url的函数去掉,直接把地址拼出来试试!?
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
templateURL function 只有2个参数
elem和attr哦。不能访问scope,因为模版请求是在scope初始化之前。可以通过属性传输,然后获取
return 'customer-'+attr.type+'.html',或者templateUrl执行还在compile之前,从哪里去注入的scope?
templateUrl的参数只有element,attrs。
如果你的type是静态的,可以这样用
你有什么问题?
把url的函数去掉,直接把地址拼出来试试!?