我在Laravel内部与Angular合作,当你看到“<%”& “%>” 中它们代表Angular中的“{{”& “}}”因为我在Laravel中使用刀片,我使用符号来区分两者。
好的,这样就可以了。这是代码,只有硬编码的ng-click-ng-click =“getPgn(1)” - 是唯一有效的代码:
<ul class="pagination" ng-model="$scope.songData">
<li><a href="javascript://" ng-click="getPgn(1)"> << </a> </li>
<li class="active"><a href="javascript://" ng-click="getPgn(<% songData.current_page %>)"><% songData.current_page %></a> </li>
<li><a href="javascript://" ng-click="getPgn(<% songData.current_page+1 %>)" ng-if="(songData.current_page+1) < (songData.last_page)"><% songData.current_page+1 %></a> </li>
<li><a href="javascript://" ng-click="getPgn(<% songData.current_page+2 %>)" ng-if="(songData.current_page+2) < (songData.last_page)"><% songData.current_page+2 %></a> </li>
<li><a href="javascript://" ng-click="getPgn(<% songData.current_page+3 %>)" ng-if="(songData.current_page+3) < (songData.last_page)"><% songData.current_page+3 %></a> </li>
<li><a href="javascript://" ng-click="getPgn(<% songData.current_page+4 %>)" ng-if="(songData.current_page+4) < (songData.last_page)"><% songData.current_page+4 %></a> </li>
<li><a href="javascript://" ng-click="getPgn(<% songData.current_page+5 %>)" ng-if="(songData.current_page+5) < (songData.last_page)"><% songData.current_page+5 %></a> </li>
<li><a href="javascript://" ng-click="getPgn(<% songData.current_page+6 %>)" ng-if="(songData.current_page+6) < (songData.last_page)"> > </a> </li>
<li><a href="javascript://" ng-click="getPgn(<% songData.last_page %>)"> >> </a> </li>
</ul>
在控制器内(角度):
$scope.getPgn = function(pageNum) {
console.log("pageNum: "+pageNum);
Song.getPage(pageNum)
.success(function (data) {
location.href = "/?page=" + pageNum;
$scope.songData = data;
mSongs = data;
$scope.loading = false;
});
}
在服务范围内(角度):
getPage : function(id) {
return $http.get('/api/songs/?page=' + id);
}
那么为什么第一个是硬编码工作而其余部分不工作?
当我查看Firebug或任何检查员时,它会显示相同的东西getPgn(2),getPgn(3)等......
为什么呢?