2016-01-21 86 views
1

我有這樣一段代碼:函數調用不正確渲染

<tr ng-repeat="convention in conventions"> 
      <td>{{ convention.Id }}</td> 
      <td>{{ convention.Title }}</td> 
      <td><a href="javascript:void(0)" ng-click="alert(convention.Id)">Edit</a></td> 
     </tr> 

我想調用一個函數像alert並通過Id爲parameter.but它不能正常顯示: firbug

有什麼建議嗎?

+0

'NG點擊= 「JavaScript的:警報(convention.Id)」' –

+1

可能的[使用警報從的NG-點擊複製指令(http://stackoverflow.com/questions/25907383/use-alert-from-ng-click-of-a-directive) – potatopeelings

回答

3

包裹alert()在控制器的功能,並把它添加到這樣的範圍:

$scope.handleClick = function(id) { 
    alert(id); 
} 

然後調用從模板這個功能:嵌入你的模板

ng-click="handleClick(contention.Id)" 

用語不只能看到相應範圍內的功能。

2

添加alert到你的範圍,像這樣在你的控制器

$scope.alert = function(i) { 
    alert(i) 
};