Answer the question
In order to leave comments, you need to log in
How to move functions outside the controller?
There is code, conditional:
// js/controller/MainController'.js
app.controller('MainController', ['$scope', function($scope) {
$scope.title = 0;
// обработчик
$scope.clickFn = nameFuncion;
}]);
// js/handler/nameFunction.js
function nameFuncion(){
$scope.title = 1; // не видит $scope, в принципе логично, но можно ли как-то исправить?
}
Answer the question
In order to leave comments, you need to log in
This is exactly where all the problems begin when you start using pliers like a hammer, simply because you are used to a hammer.
You can do this:
app.controller('MainController', ['$scope', function($scope) {
$scope.title = 0;
// с помощью bind() можно явным образом задать контекст
$scope.clickFn = nameFuncion.bind($scope);
}]);
function nameFuncion(){
this.title = 1;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question