Answer the question
In order to leave comments, you need to log in
Why use OOP constructs in an AngularJS application?
I came across one application and it interested me. As far as I understand, OOP principles are used in AngularJS under the hood, but here's why and for what purpose they should be used in service controllers and directives. I would be very grateful if someone could sensibly comment on the following code snippets:
1. Factory:
fcatory('Fac', function () {
return new Contr();
function Constr () {
this.tratata = 123;
}
Constr.prototype.fu = function () {}
})
.directive('myDirective', function () {
function MyController () {
this.x = 1231234;
}
MyController.prototype.fu = function () {}
function Template () {
// тут логика конструктора
}
return {
restrict: E,
*****,
template: new Template();
controller: function($scope, $element, $attrs) {
var myController = new MyController($scope, $element, $attrs);
$scope._myController = myController;
}
}
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question