angularjs 中directive的scope问题

https://img.mukewang.com/5ba342c00001c32906290532.jpg

重新编辑

各位请看:link中我可以输出scope.type
可是在templateURL中scope.type为undefined
有点不懂directive的scope了,请各位指教谢谢


慕码人2483693
浏览 690回答 1
1回答

慕盖茨4494581

templateURL function 只有2个参数&nbsp;elem&nbsp;和&nbsp;attr哦。不能访问scope,因为模版请求是在scope初始化之前。可以通过属性传输,然后获取return 'customer-'+attr.type+'.html',或者... link:&nbsp;function(scope)&nbsp;{ &nbsp;&nbsp;scope.customerUrl&nbsp;=&nbsp;'customer-'+scope.type+'.html'}, template:&nbsp;'<div&nbsp;ng-include="customerUrl"></div>'...
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript