ng-click函数被调用,但数组数据没有显示在AngularJS的HTML页面中?



ng-click函数在选项卡上正确调用,我从服务中正确获取列表,但数据未反映在HTML页面中我不明白我的代码中有什么问题请检查我的代码并告诉我我错了哪个地方?

/**
* @Summary:getUserCategory function, to get the User selected Category.
* @param:   callback
* @return:  callback(response) .
* @Description: 
*/
//Defining function for getUserProfile in service 
$scope.getUserCategory = function () {
var data = {
userTypeKeyId: Number(AUTH.userTypeKeyId),
fieldKeyId: Number(AUTH.defaultFieldKeyId)
};
IntermediaryDashboardService.getIntCategory(function (response) {
if (response != null) {
if (response.data.isSuccess) {
$scope.userCategories = response.data.userCategories;
}
}
}, data);
};
/**
* @Summary: getIntCategory function, to get the IntCategory
* @param:   callback, data
* @return: 
* @Description:
*/	
this.getIntCategory = function (callback, data) {
var url = '/api/userCategories/filter/list/each';
$http({
method: 'POST',
url: url,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data
}).then(
function (response) {
//Success Function
callback(response);
},
function (response) {
//Failure function
callback(null);
}
}
<ul ng-repeat="category in userCategories" class="ng-cloak">
<li style=" padding-top: 11px;">
<a href="#" ng-click="getAlbumInIntermediary(category.categoryKeyId)">
{{category.categoriesDto.categoryName}}
</a>
</li>
</ul>

简单使用

ng-if="intermediaryAlbumCount.length"

因为 0 被视为虚假。

但数据不会显示在 HTML 页面中

不要将回调与承诺混合使用。

您在服务中执行异步调用并解析原始承诺。因此,创建新的承诺并将其解析到您的控制器中,如下所示:

this.getIntCategory = function (callback, data) {
var deferred = $q.defer(); 
var url = '/api/userCategories/filter/list/each';
$http({
method: 'POST',
url: url,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data
}).then(function (response) {
deferred.resolve(response.data);
},
function (response) {
deferred.resolve({});
});
return deferred.promise;
}

现在在控制器中,您可以写为:

$scope.getUserCategory = function () {           
IntermediaryDashboardService.getIntCategory().then(function (result) {
$scope.userCategories = response.data.userCategories;                           
}, function (result) {
alert("Error: No data returned");
});    
}  

小提琴

最新更新