在指令和控制器angularjs之间传递信息 [英] Pass information between directive and controller angularjs
本文介绍了在指令和控制器angularjs之间传递信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下一条指令
angular
.module('01')
.directive('tableSortable', tableSortable);
/** @ngInject */
function tableSortable() {
return {
restrict: 'E',
transclude: true,
templateUrl: 'app/components/tabla/tableSortable.html',
scope: {
columns: '=',
data: '=',
sort: '=',
onclickRow: '='
}
还有下一个显示表格的html
and I have the next html that shows a table
<tbody>
<tr ng-click="click(object)" ng-repeat="object in data | orderBy:sort.column:sort.descending | orderBy:sort.column:sort.descending | startFrom:currentPage*pageSize | limitTo:pageSize">
<td
ng-repeat="key in object"
ng-if="key != '$$hashKey'" >
{{object[columns[$index].variable] | customFilter : getFilterOfColumn(columns[$index].variable)}}
</td>
</tr>
</tbody>
我还有另一个html,我将其称为指令
I have this other html where I call the directive
<table-sortable onclick-row="main.onclickRow(msg)"
columns="main.columnsBusquedas" data="main.rowsBusquedas" sort="main.sortBusquedas">
</table-sortable>
此控制器具有onclickRow(msg)函数,我要在其中获取用户单击的行
And this controller with a function onclickRow(msg) where I want to take the row that the users click on
function onclickRow(msg){
$log.debug(msg);
}
此代码不起作用...能帮我吗?
This code didn't work... Could you help me please?
谢谢.
推荐答案
更改绑定函数的指令部分,应使用&
而不是=
Change your directive part where you bind function, you should use &
instead of =
function tableSortable() {
return {
restrict: 'E',
transclude: true,
templateUrl: 'app/components/tabla/tableSortable.html',
scope: {
columns: '=',
data: '=',
sort: '=',
click: '&onclickRow' // this how we call function from directive...
}
在HTML中,如下更改您的ng-click
.
In HTML change your ng-click
like below..
<tbody>
<tr ng-click="click({'msg':object})" ng-repeat="object in data | orderBy:sort.column:sort.descending | orderBy:sort.column:sort.descending | startFrom:currentPage*pageSize | limitTo:pageSize">
<td
ng-repeat="key in object"
ng-if="key != '$$hashKey'" >
{{object[columns[$index].variable] | customFilter : getFilterOfColumn(columns[$index].variable)}}
</td>
</tr>
</tbody>
这篇关于在指令和控制器angularjs之间传递信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文