In vanilla javascript I can do:
run();
function run() {};
In angular though it seems I have to predefine all the functions on a scope before I can run them:
app.controller('MainCtrl', function($scope) {
$scope.fxn = function() {
$scope.status = 'working';
};
$scope.fxn();
});
Because this throws the error TypeError: Object #<Object> has no method 'fxn':
app.controller('MainCtrl', function($scope) {
$scope.fxn();
$scope.fxn = function() {
$scope.status = 'working';
};
});
Am I missing something? Is angular enforcing a best-practice?