有没有办法在指令中对src求值?这是我的代码片段:
app.directive('loadTemplate', function ($templateCache,$compile) {
return {
restrict: 'A',
scope: {
src: '@'
},
template:$templateCache.get("'{{src}}'")
};
});发布于 2018-03-05 14:11:39
使用templateUrl,它可以接受一个函数:
app.directive('loadTemplate', function ($templateCache,$compile) {
return {
restrict: 'A',
scope: {
src: '@'
},
templateUrl: function (elem, attrs) {
return attrs.src;
}
};
});在您的html中:
<loadTemplate src="xxx.html"></loadTemplate>https://stackoverflow.com/questions/49102722
复制相似问题