angular js,为什么我的数据不可视化?
angular js, why my data don't visualize?
你好,我正在努力学习 angular,但比我想象的要难。
我只想可视化控制器内数组的一些值,但在浏览器中似乎显示任何内容。
这里是代码:
<body ng-app="APP">
<div ng-controller="theController">
<b ng-repeat="item in items">{{item.title}}</b>
</div>
<script>
angular.module('APP',[])
.controller ('theController',['$scope',function($scope){
$scope.items[
{'title':'a','type':1},
{'title':'b','type':2},
{'title':'c','type':1},
{'title':'d','type':4}
]
}])
</script>
</body>
</html>
我只是复制了一个现有的教程,所以为什么我可以看到标签内的任何内容?
只是改变
发件人:
$scope.items[
{'title':'a','type':1},
{'title':'b','type':2},
{'title':'c','type':1},
{'title':'d','type':4}
]
到:
$scope.items = [
{'title':'a','type':1},
{'title':'b','type':2},
{'title':'c','type':1},
{'title':'d','type':4}
]
工作JsFiddle
这是一个非常小的语法错误不用担心 --Angular真的很简单很神奇!
angular.module('APP',[]) //app core module
.controller ('theController',['$scope',function($scope){ //first controller to hold models
$scope.items = [ //**Here = was missing; that was your minor mistake**//first model as array of objects
{'title':'a','type':1},
{'title':'b','type':2},
{'title':'c','type':1},
{'title':'d','type':4}
]; //**semicolon was missing; putting is good practice**
}]);//**semicolon was missing; putting is good practice**
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!-- app init and letting div to be controlled by our controller named as theController -->
<div ng-app='APP' ng-controller='theController'>
<ol >
<!-- angular magical iteration on model, on items in this case -->
<li ng-repeat='item in items'>
Index:{{$index}} ==> {{item.title}} {{item.type}}
<li>
</ol>
</div>
帮助愉快!
你好,我正在努力学习 angular,但比我想象的要难。 我只想可视化控制器内数组的一些值,但在浏览器中似乎显示任何内容。
这里是代码:
<body ng-app="APP">
<div ng-controller="theController">
<b ng-repeat="item in items">{{item.title}}</b>
</div>
<script>
angular.module('APP',[])
.controller ('theController',['$scope',function($scope){
$scope.items[
{'title':'a','type':1},
{'title':'b','type':2},
{'title':'c','type':1},
{'title':'d','type':4}
]
}])
</script>
</body>
</html>
我只是复制了一个现有的教程,所以为什么我可以看到标签内的任何内容?
只是改变
发件人:
$scope.items[
{'title':'a','type':1},
{'title':'b','type':2},
{'title':'c','type':1},
{'title':'d','type':4}
]
到:
$scope.items = [
{'title':'a','type':1},
{'title':'b','type':2},
{'title':'c','type':1},
{'title':'d','type':4}
]
工作JsFiddle
这是一个非常小的语法错误不用担心 --Angular真的很简单很神奇!
angular.module('APP',[]) //app core module
.controller ('theController',['$scope',function($scope){ //first controller to hold models
$scope.items = [ //**Here = was missing; that was your minor mistake**//first model as array of objects
{'title':'a','type':1},
{'title':'b','type':2},
{'title':'c','type':1},
{'title':'d','type':4}
]; //**semicolon was missing; putting is good practice**
}]);//**semicolon was missing; putting is good practice**
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!-- app init and letting div to be controlled by our controller named as theController -->
<div ng-app='APP' ng-controller='theController'>
<ol >
<!-- angular magical iteration on model, on items in this case -->
<li ng-repeat='item in items'>
Index:{{$index}} ==> {{item.title}} {{item.type}}
<li>
</ol>
</div>
帮助愉快!