To override functionality of a factory, you need to create another class and
set the prototype as new FactoryClass. Following code change will do the magic
and it works like a charm. :)
function MyCtrl($scope, MyObject, MyObjectWithParam) {
var NewObject = function () {
MyObject.apply(this, arguments);
};
NewObject.prototype = new MyObject();
NewObject.prototype.getText = function () {
return 'override';
}
MyObjectWithParam.prototype.getText = function () {
return 'override';
}
var obj1 = new NewObject(),
obj2 = new MyObjectWithParam("hello"),
obj3 = new MyObjectWithParam("world");
obj1.constructor.prototype.getText = function () {
return 'aa';
}
$scope.text = [
obj1.getText(),
obj2.getText(),
obj3.getText()
];
}
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.