当我编译代码时,有一个带有角度的错误。
代码是从一本书中编写的,当我使用问题末尾的代码加载页面时,它可以正常工作。
我读过的内容似乎有两个问题。我在哪里放置$ scope和$ compile代码?
大多数情况下,问题是如何使用角度JS按钮加载文档就绪触发器?
或者我应该总是加载角度js并隐藏代码吗?
<div id="myTabs">
<div class="menu">
<ul class= "tabs">
<li ><a href="#a" id="listA">LIST</a></li>
<li ><a href="#b" id="gridB">GRID</a></li>
<li ><a href="#b" id="listC">GRID</a></li>
</ul>
</div>
<div class="container" style="margin-top:100px">
<div id="a">
</div>
<div id="b">
<ul class="gallery-items" id="grid">
</ul>
</div>
<div id="c" >
<div ng-controller="myController">
<div ng-repeat="item in items">
<img ng-src="{{item.img}}" />
{{item.description}}<br>
Rating: {{item.rating}} stars<br>
<span ng-repeat="idx in stars"
ng-class=
"{true: 'star', false: 'empty'}[idx <= item.rating]"
ng-click="adjustRating(item, idx)">
</span>
<hr>
</div>
</div>
</div>
</div>
ajax.js有一个调用#c选项卡加载
的函数$(document).ready(function(){
$('#listC').click(function(){
angular.module('myApp', [])
.controller('myController', ['$scope', function($scope) {
$scope.stars = [1,2,3,4,5];
$scope.items = [100];
$.ajax({
type:'post',
url:'changeView.php',
data:{action: 'getGrid'},
success:function(data){
var data = JSON.parse(data);
for (i=0;i<data.length;i++) {
var imageLI = makeImage(data[i]['imageID'], data[i]['name'], data[i]['desc']);
$scope.items[i] = imageLI;
}
}
});
console.log($scope.items);
$scope.adjustRating = function(item, value){
item.rating = value;
};
}]);
});
$('#listC').trigger('click');
function makeImage(ID, name, description){
var image = {
description: description,
img: '../uploads/'+name,
rating: 4
}
return image;