I have multiple controllers for multiple routes:
app.controller('FirstController', function ($scope) {
$scope.func = function () {
console.log('route 1');
}
}
app.controller('SecondController', function ($scope) {
$scope.func = function () {
console.log('route 2');
}
}
...
and a directive that uses the $scope.func
, this way:
app.directive('thedirective', function () {
return {
link: function (scope, $element, attrs) {
$scope.func(attrs.thedirective);
}
}
});
$scope.func
is different in each controller. I expect the $scope.func to log "route 1" when we are in route1 and FirstController is the current controller and to log "route 2" when in route 2, but only "rout 1" is what I get in console. may you please tell me why changing route doesn't change $scope of directive?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…