我想,我在控制器模型,是不是普通的物体,像Number
,Boolean
,String
,Object
,Array
,而是由函数构造函数创建的对象。
AngularJS中可能吗?
这是我的html:
<body ng-app="MyApp" ng-controller="MyController">
<input ng-model="model.text" type="text"/>
</body>
和我的脚本:
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'};
}])
在constant
不需要它被包裹在一个函数...
angular.module('MyApp',[]).
constant('MyModel',function(text){
this.text = text;
}).
// ...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句