내 경로 파일 내 HEADER.html 현재의 파셜에서각도 경로를 사용하여 현재 상태에서 활성 클래스를 설정하는 방법은 무엇입니까?
app.config(["$routeProvider",function($route)
{
$route.when("/",{
templateUrl : "partials/index.html",
controller : "AppCtrl"
}).when("/contact",{
templateUrl:"partials/contact.html",
controller:"ContactCtrl"
}).
when("/about-us",{
templateUrl:"partials/about.html",
controller:"AboutCtrl"
}).
when("/gallery",{
templateUrl:"partials/gallery.html",
controller:"GalleryCtrl"
}).
otherwise({
redirectTo:"/"
});
}]);
을 내가 HeaderCtrl 컨트롤러를 사용하고
app.controller("HeaderCtrl",["$scope","$location",function($scope,$location)
{
$scope.location=$location.path().replace("/","");
}]);
내 HEADER.html 현재
<ul ng-controller="HeaderCtrl">
<li ng-class="{active:location===''}"><a href="#">home</a></li>
<li ng-class="{active:location==='about-us'}"><a href="#/about-us">about us</a></li>
<li ng-class="{active:location==='gallery'}"><a href="#/gallery">gallery</a></li>
<li ng-class="{active:location==='contact'}"><a href="#/contact">contact</a></li>
</ul>
때 페이지를 다시로드 (실제 새로 고침) 그럼 그것은 작동 클래스 즉, 각각의 리튬에 적용됩니다하지만 내가 (메뉴 항목을 클릭하여) 경로를 변경하면 작동하지 않습니다
라우트가 변경 될 때 컨트롤러에서'$ scope.location'을 변경하지 않았기 때문입니다. – Brett
그래, 나는 그것이 사실이라고 생각한다. 어떻게 극복 할 수 있을까? – ahhmarr