我创建了一个指令,该指令只是将存储在.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>
@瓦列里·科兹洛夫这似乎没有工作。 –