我在点击按钮时动态添加指令。 当我尝试从其链接函数更新动态生成的指令模板时,它不会更新,但我在控制台中获取更新的值。 我的代码是:: MAIN指令::
app.directive("loadingDivStart",["$compile",function($compile){
return{
restrict:"A",
link:function ($scope, $elem, $attr){
console.log('me');
$elem.on('click',function(e){
newElement = $compile("<div id='loaderContainer' loading-directive mywindow='windowProp' my-timer='timer' style='height:100%;'></div>")($scope);
$('body').append(newElement);
});
}
}
}])
动态指令
app.directive("loadingDirective", ["$timeout","$interval", function ($timeout,$interval) {
return {
restrict: "A",
scope: {
// mytimer: "=",
windowProp: "=mywindow",
myTimer: "="
},
template: "<div class='loader' style='width:{{windowProp.width}}px;height:{{windowProp.height}}px;'><div class='svgAnimation'>{{fromVal}}</div></div>",
link: function (scope, elem, attrs) {
scope.fromVal = '08:00';
$timeout(function(){
scope.fromVal = 'Hello';
console.log("Changed");
}, 5000);
}
}
}]);
在 $ timeout
之后, fromVal 的值未更新