您的位置:首页 > 运维架构

angular 指令中绑定父 scope 的方法

2016-04-27 00:00 711 查看
摘要: angular 指令中绑定父 scope 的方法

// 指令

<con3-list data="ui" title="UI设计专业" zan="zan(teacherid)"></con3-list>

// 控制器定义 zan 方法,

'use strict';

mobile.controller('ctrl', ['$scope',function($scope){

$scope.zan = function (teacherid) {

if(!$scope.userInfo){

alert('您还没有登录, 请登录后为老师点赞!');

common.doReg('51mobile');

return;

}

}

}]);

// 指令

mobile.directive('con3List', function () {

return {

restrict : 'EA',

replace : true,

scope : {

data : '=',

title : '@',

zan : '&' // 绑定 scope 的 zan 方法

},

// transclude : true,

template : '<div class="con3-list"></div>',

link : function ($scope, ele, attr) {

ele.bind('click', function(){

// 调用zan方法并传递参数

$scope.zan({teacherid:'89'});

});

}

}

})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: