我认为$ scope.tutor.noiday是一个数组,但我不明白为什么我会收到这个错误。请帮帮我。
这是我的代码controller.js
$scope.daytai = ['Tutor house', 'Student house', 'Other'];
$scope.dashbroadTutorInfo = function(){
// find tutor by username - current_user
$scope.username = $rootScope.current_user;
$scope.tutor = tutorFactory.getTutorByUsername($scope.username)
.then(function(response){
if(response.data){
$scope.tutor = response.data.giasu;
}
});
}
// check exist noiday
$scope.existDay = function(item){
return tutorFactory.exists($scope.tutor.noiday, item);
}
这是我的service.js
// check exist item in array
tutorFactory.exists = function(arr, item){
return arr.indexOf(item) > -1;
}
HTML
<form ng-submit="updateJob()">
<input type="hidden" ng-model="tutor._id">
<div class="form-group">
<label class="control-label col-sm-3" for="noiday">Nơi dạy:</label>
<div class="col-sm-8">
<div ng-repeat="c in daytai">
<label><input type="checkbox" name=""
ng-model="tutor.noiday" ng-checked="existDay(c)"
ng-click="selNoiDay(c)"/><span></span>{{c}}</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-2 col-md-offset-3">
<button type="submit" class="base-text-color">Submit</button>
</div>
<div class="col-md-6"></div>
</div>
</form>
提前致谢
答案 0 :(得分:0)
试试这个,
IniLineFormatter
在工厂
$scope.dashbroadTutorInfo = function(){
// find tutor by username - current_user
$scope.username = $rootScope.current_user;
tutorFactory.getTutorByUsername($scope.username)
.then(function(response){
if(response.data){
$scope.tutor = response.data.giasu;
// check exist noiday
$scope.existDay = function(item){
return tutorFactory.exists($scope.tutor.noiday, item);
}
}
});
}
希望有所帮助