我是angularJS的新手。我正在使用离子框架进行android应用程序开发。在我的项目中,我调用webservice并获取其响应并将该响应附加到scope变量以获取视图上的数据。首次调用Web服务并按预期更新视图,但是当我再次调用不更新数据的服务时。由于某些参考丢失问题,似乎ng-repeat不起作用。但我无法找到解决方案。虽然我已经通过使用apply()尝试了不同的解决方案,正如其中一个堆栈溢出帖子中提到的那样。以下是将web服务响应附加到范围变量的代码。
$http(req).then(function (response) {
if (response.data.IsSuccess) {
console.log("data = " + JSON.stringify(response.data));
console.log('Response is '+response.data.IsSuccess);
$scope.companies = response.data.Response.Companies;
}
及以下是用于更新视图的代码行
<div class="col col-100" ng-repeat="company in companies">
任何帮助或建议
以下是调用webservice来更新我的数据的登录代码
function callLogInService(userName, password){
console.log("user name is " +userName);
console.log("password is " + password);
var req = {
method: 'POST',
url: ApiUrl + '/api/User/LoginUser',
headers: {
'Content-Type': 'application/json'
},
data: {
Email: userName,
Password: password
}
}
$ionicLoading.show({
template: 'Signing in...'
});
$http(req).then(function (response) {
if (response.data.IsSuccess) {
console.log("data = " + JSON.stringify(response.data));
console.log('Response is '+response.data.IsSuccess);
var userID = response.data.Response.AppUserId;
var userName = response.data.Response.AppUserName;
setUserName(userName);
setUserId(userID);
$rootScope.appUserName;
var userIdFromSession = getUserID;
if(undefined == $rootScope.companyIdForSubscription
|| $rootScope.companyIdForSubscription == 0){
console.log("id is undefined for subscription");
} else {
console.log("company subscription id is " + $rootScope.companyIdForSubscription);
$scope.subscribe($rootScope.companyIdForSubscription);
}
$scope.close();
$scope.setVisibilityOdSideMenuIcons();
$scope.getAllCompanies();
}
else {
showErrorAlertDialogue(response.data.ErrorMessage);
}
}, function (reason) {
console.log('reason is ' + reason.data);
$log.info('reasonf log is' + reason) ;
showErrorAlertDialogue("Please check your internet connection.");
}).finally(function () {
console.log("finally is called");
$ionicLoading.hide();
$ionicPopup.close()
});
}
$ scope.getAllCompanies();这一行再次呼叫服务