带有 transclude 的指令,数据绑定在 templateUrl 中不起作用
Directive with transclude, data binding not working in templateUrl
我有一个 transclude:true 指令。但是,数据绑定在我使用 template:"" 时有效,但在我使用 templateUrl:"""
时无效
您可以在下面找到我的指令。 rsCarousel.html 模板包含与模板"" 属性.
相同的代码
使用模板 属性 时,我在屏幕上看到了 vm.carouselId,但在使用 templateUrl 属性.
时却没有
这是为什么?
谢谢,
(function () {
'use strict';
angular.module('skynetDashboard').directive('rsCarouseli', carouseli);
function carouseli(){
var directive = {
restrict:"EA",
scope:{
carouselData:"=",
carouselId:"@",
carouselOptions:"@"
},
transclude:true,
templateUrl:"js/directive/rsCarousel.html",
//template:"<strong>ID: {{vm.carouselId}}</strong><ul ng-transclude></ul>",
bindToController:true,
controllerAs:"vm",
link:link,
controller:controller
}
return directive
function link(scope){
console.log(scope.vm)
}
controller.$inject = [""]
function controller(){
}
}
})();
这很奇怪,范围绑定在这两种情况下都应该有效。
确保您的模板文件未被浏览器缓存(并使用旧版本)。
我有一个 transclude:true 指令。但是,数据绑定在我使用 template:"" 时有效,但在我使用 templateUrl:"""
时无效您可以在下面找到我的指令。 rsCarousel.html 模板包含与模板"" 属性.
相同的代码使用模板 属性 时,我在屏幕上看到了 vm.carouselId,但在使用 templateUrl 属性.
时却没有这是为什么?
谢谢,
(function () {
'use strict';
angular.module('skynetDashboard').directive('rsCarouseli', carouseli);
function carouseli(){
var directive = {
restrict:"EA",
scope:{
carouselData:"=",
carouselId:"@",
carouselOptions:"@"
},
transclude:true,
templateUrl:"js/directive/rsCarousel.html",
//template:"<strong>ID: {{vm.carouselId}}</strong><ul ng-transclude></ul>",
bindToController:true,
controllerAs:"vm",
link:link,
controller:controller
}
return directive
function link(scope){
console.log(scope.vm)
}
controller.$inject = [""]
function controller(){
}
}
})();
这很奇怪,范围绑定在这两种情况下都应该有效。
确保您的模板文件未被浏览器缓存(并使用旧版本)。