我創建了一個指令,該指令只是將存儲在.html中的一些div標籤轉換爲單個元素。我注意到該指令只在頁面重新加載時編譯,當路由改變時指令不會被激活,我知道你可以使用$ routeChangeSucess或$ scope.watch來檢測路由改變,但在我的情況下,我沒有使用在這個目錄中的鏈接函數,我只使用templateUrl。在路由改變時重新加載/重新運行此指令的最佳方式是什麼?下面是我的代碼;重新運行路線變化中的所有角度對象指令(不僅鏈接功能)
stockfront.factory('directiveConfig', function(){
factory = {};
factory.returnConfig = {
scope : true,
restrict: "E",
replace: true,
templateUrl : "",
template : "",
transclude : true,
link : "",
combine: ""
};
return factory;
});
stockfront.directive("mainDiv", function(directiveConfig){
directiveConfig.returnConfig.templateUrl = "./template/mainDiv.html";
return directiveConfig.returnConfig;
});
這就是我想@Valery科茲洛夫:
stockfront.run(function($rootScope) {
$rootScope.routeChange = false;
$rootScope.$on("$routeChangeSuccess", function() {
// handle route changes
$rootScope.routeChange = true;
});
});
然後在html:
<main-div ng-if="$root.routeChange"><main-div>
@瓦列裏·科茲洛夫這似乎沒有工作。 –