I am new to AngularJS and I am still being a bit confused about calling an custom method of an object and if there is a more lazy way to do it:
https://jsfiddle.net/f4ew9csr/3/
<div ng-app="myApp" ng-controller="myCtrl as myCtrl">
<h1 ng-click="myCtrl.display()">Click me!</h1>
<h2>{{ myCtrl.myValue }}</h2>
</div>
var app = angular.module('myApp', []);
app.controller('myCtrl', function() {
var self = this;
this.myValue = "Hello world!"
this.display = function() {
self.myValue = MyObject.display();
};
});
var MyObject = new function() {
var i = 0;
this.display = function() {
alert("Change h2");
return "Hey";
};
this.update = function() {
i += 1;
return i;
}
};
So when the h1 is clicked the h2 gets changed and an alert pops up. But my question is that I want to call a custom object method with ng-click in a more efficient way than I am doing right know.
And how could I run MyObject.update() with setInterval so it constantly changes my h2 header without jquery?