我是 AngularJS 中的新手,我有一个问题,请向我解释我的错误原因。首先,我有一个工厂名称CategoryParent
,此函数声明为这样,
routerApp.factory('CategoryParent', function($http) {
var categoryParentFactory = {};
var hostCMSAPI="http://***.***.***.***:****";
// get all categories
categoryParentFactory.allCategoryParents = function() {
console.log("call get allCategoryParents");
return $http.get(hostCMSAPI+'/api/categoryparents/');
};
.......
并且控制器调用此函数名为categoryParentController
:
.controller('categoryParentController', function(CategoryParent,$scope) {
console.log("cateParent ctrl");
$scope.processing=true;
$scope.dataList=[];
$scope.getAllCategoryParents=function(){
CategoryParent.allCategoryParents().success(function(response){
$scope.processing = false;
$scope.list=response;
});
我这样使用ui.router
(嵌套视图):
.state('home.cateParentMenu',{
url:'/cateParentMenu',
templateUrl:'categoryParentTop.html',
controller:'categoryParentController',
controllerAs:'categoryParent'
})
父视图触发控制器功能在这里:
此页面演示了嵌套视图。
<a ui-sref=".list" class="btn btn-primary">List</a>
<a ui-sref=".paragraph" class="btn btn-danger">Paragraph</a>
<a ui-sref=".cateParentMenu" class="btn btn-warning" ng-click="getAllCategoryParents()">cateParentMenu</a>
最后,儿童观点来到这里
数据显示 {{处理}} {{列表}} {{item.cate_parent_name}} <ul class="nav navbar-nav" >
data show
{{processing}}
{{list}}
<li data-ng-repeat="item in list.data"><a ui-sref=".detail({cate_parent_id:item.cate_parent_id})" ng-click="getById(item.cate_parent_id)" ui-sref-active="active" id="{{item.cate_parent_id}}">{{item.cate_parent_name}}</a></li>
</ul>
<div class="col-sm-6">
<div ui-view=""></div>
<!--<div ui-view="serviceRef"></div>-->
<!--<div ui-view="categoryRef"></div>-->
</div>
我设置$scope.list
和$scope.processing
以将结果传输到视图。但在视图中我显示{{list}}
,没有出现任何内容{{processing}} = true
???
为什么呢?请帮助我,非常感谢您的所有建议。
答案 0 :(得分:0)
控制器
将$scope.dataList=[];
修复为$scope.list=[];