我是开始从angularJS文档学习AngularJS并尝试使用Factory Method处理服务。尝试注入自定义服务时,我收到角度注入器错误。错误Error: $injector:modulerr Module Error
我已经工作了几个小时,仍然无法找到解决问题的方法。
的script.js
angular.module('myApp',['repeater']).controller('FormController',['ageGenderController',function FormController(ageGenderController){
this.ageOptions = ageGenderController.ageArrays;
this.genderOptions = ageGenderController.genderArrays;
var submit = function()
{
this.result = "has been submitted";
};
}]);
repeater.js
angular.module('repeater', []).factory('ageGenderController',function(){
var ageArray = new Array(100);
for(var i= 17; i <ageArray.length; i++)
{
ageArray.push(i);
}
var genderArray = ['Male','Female','Other'];
return
{
ageArrays: ageArray,
genderArrays: genderArray
};
});
的index.html
<div ng-app="myApp" ng-controller="FormController as myForm">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" ng-model="myForm.name" placeholder="Enter your Name" required>
</div>
<div class="form-group">
<label>Email</label>
<input type="email" class="form-control" ng-model="myForm.email" placeholder="Enter your Email" required>
</div>
<div class="form-group">
<label>Phone</label>
<input type="number" minlenght="10" maxlength="10" class="form-control" placeholder="Enter your Phone Number" ng-model="myForm.phone" required>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" placeholder="Password" ng-model="myForm.password" required>
</div>
<div class="form-group">
<label>Select your age</label>
<select ng-model="myForm.ageSelect">
<option ng-repeat="c in myForm.ageOptions">{{c}}</option>
</select>
</div>
<div class="form-group">
<label>Gender</label>
<select ng-model="myForm.genderSelect">
<option ng-repeat="d in myForm.genderOptions">{{d}}</option>
</select>
</div>
<div class="form-group">
<button ng-click="myForm.submit()" class="btn-primary">Submit</button>
</div>
{{myForm.result}}
</div>