after trying the entire day here I am...
Angularjs newbie, though decent knowledge in js, I believe for some of you this question should be a no-brainer.
Suppose we have the following angular mini app:
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body ng-app="myApp">
<div ng-controller="ctrl">
<h1 ng-click="toggle()">{{firstname}}</h1>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('ctrl', function($scope) {
$scope.firstname = "adam";
$scope.toggle = function() {
$scope.firstname = "eva";
}
});
</script>
</body>
</html>
I am able to register further controller afterwards (i.e. from the console), as follows:
// ought to overwrite the behaviour of the old one
app.controller('ctrl', function($scope) {
$scope.firstname = "adam";
$scope.toggle = function() {
$scope.firstname= $scope.firstname == 'adam' ? 'eva' : 'adam';
}
});
How on earth do I invoke programmatically the constructor of the latter controller in order to get new behaviour for the toggle function (preferable from the console)???
Edit
Accessing the scope of the controller and assign toogle
to the new function does not really help in case the function refers to variables declared inside the constructor but outside the functions body.
` tag and this overrides the toggle functionality, but I don't know if that's what you were looking for
– MannfromReno Feb 02 '17 at 19:31