我正在生成基於行大小的分頁按鈕。我的問題是,當我在我的AngularJS函數中創建按鈕並將其綁定到按鈕正常顯示的元素上時,但ng-click不起作用。如何用ng-click綁定AngularJS按鈕?
這裏是我的代碼:
var app = angular.module('myapp', []);
var url = "<?php echo base_url(); ?>"+"index.php/";
var rowcount = <?php echo $this->session->userdata("count"); ?>;
app.controller('myctrl', function($scope, $http, $sce)
{
$http.get(url+"exammanager/0/10").then(function(response)
{
$scope.myData = response.data.exams;
$scope.refresh();
});
$scope.refresh = function()
{
$http.get(url+"exammanager/0/10").then(function(response)
{
$scope.myData = response.data.exams;
num = Math.ceil(rowcount/10);
counter = 0;
var buttons = "";
for(i = 1;i <= num; i++)
{
if(i != num)
buttons += " <button ng-click=\"pagescopeclick(\'"+url+"index.php/exammanager/"+counter+"/10\')\" >"+i+"</button> |";
else
buttons += " <button ng-click=\"pagescopeclick(\'"+url+"index.php/exammanager/"+counter+"/10\')\" >"+i+"</button> ";
counter = counter + 10;
}
$scope.count = $sce.trustAsHtml(buttons);
});
}//Refresh controller
$scope.pagescopeclick = function(val)
{alert();
$http.get(val).then(function(response)
{
$scope.myData = response.data.exams;
});
}//pagescopeclick move to the next page without refresh
});
你必須注射到DOM之前編譯元素,你可以使用'$編譯'爲相同.. –