I want, my model in the controller, to be not a plain object like Number
,Boolean
,String
, Object
,Array
, but an object created by function-constructor.
Is it possible in AngularJS?
Here is my html:
<body ng-app="MyApp" ng-controller="MyController">
<input ng-model="model.text" type="text"/>
</body>
and my script:
angular.module('MyApp',[]).
constant('MyModel',function(){
var MyModel = function(text){
this.text = text;
};
return MyModel;
}).
controller('MyController',
[
'$scope',
'MyModel',
function(
$scope,
MyModel
){
//Does not work
$scope.model = new MyModel('dummy text');
//Works
//$scope.model = {text:'dummy text'};
}])