我有一个angularJS指令,它将templateUrl属性设置为一个函数,它根据服务函数确定要使用的模板。当服务完成某个作业(由指令内的事件触发)时,它会触发一个回调,它会修改指令的范围,并且应该调用"重绘"该指令。通过重绘,我的意思是调用templateUrl函数,并根据服务内部的新值正确更新模板。我不知道如何调用这个重绘/更新,谷歌对我的问题毫无用处。
application.directive('loginform', ['authorization', function(auth) {
return {
restrict: 'E',
transclude: true,
replace: true,
templateUrl: function(element, attributes)
{
if(auth.token() != "")
{
return "/client/templates/loginForm_disabled.html";
}
else
{
return "/client/templates/loginForm_enabled.html";
}
},
link: function($scope, element, attributes) {
$scope.username = "";
$scope.password = "";
$scope.message = "";
//this function is called on a button press.
$scope.login = function() {
auth.login($scope.username, $scope.password, function (success) {
if(!success)
{
$scope.message = "Login was unsuccessful";
}
else
{
$scope.message = "";
}
//call a redraw/update of the template
});
}
}
}
}]);
答案 0 :(得分:0)