나는 여러 경로에 대해 여러 개의 컨트롤러가 있습니다방법 여러 컨트롤러의 기능을 재사용
app.controller('FirstController', function ($scope) {
$scope.func = function() {
console.log('route 1');
}
}
app.controller('SecondController', function ($scope) {
$scope.func = function() {
console.log('route 2');
}
}
...
과 $scope.func
를 사용하는 지시어,이 방법 :
app.directive('thedirective', function() {
return {
link: function (scope, $element, attrs) {
$scope.func(attrs.thedirective);
}
}
});
$scope.func
각 컨트롤러에서 다른를 . $ scope.func가 route1에 있고 FirstController가 현재 컨트롤러이고 경로 2에 "route 2"를 기록하지만 "rout 1"만 콘솔에있는 경우 "$ route.func"가 기록 될 것으로 예상합니다. 왜 경로를 변경해도 $ 지침의 범위가 변경되지 않는지 제발 알려주시겠습니까?
어쩌면 내 솔루션이 도움이 될 수 있습니까? http://stackoverflow.com/questions/26921071/initialize-scope-variables-for-multiple-controllers-angularjs/26921599#26921599 – arman1991