ng按角度方向重复
ng-repeat in angular directive
我正在尝试创建一个带有一些额外功能的自定义select指令。
.directive('singleSelect',function(){
restrict:'A'
scope:{
model:'='
}
link:function(elem,scope,attrs){
elem.bind('click',function(){
scope.vModel=model.slice(0,20);
});
controller:function($scope)
{
//some more manipulation with model and assign to vModel
}
template:'<ul><li ng-repeat="item in vModel"></li><ul>'
});
问题是,我正在将值分配给vModel,但它没有在模板中更新。
之所以会发生这种情况,是因为您正在更新jQuery选择器中的范围变量。您需要使用$scope$申请以启动摘要周期,该周期将更新您的模型。
试试这个:
.directive('singleSelect',function(){
restrict:'A'
scope:{
model:'='
}
link:function(scope, elem, attrs){
elem.bind('click',function(){
scope.$apply(function(){
scope.vModel=model.slice(0,20);
})
});
controller:function($scope)
{
//some more manipulation with model and assign to vModel
}
template:'<ul><li ng-repeat="item in vModel"></li><ul>'
});
注意,链接函数中的参数按如下顺序排列:链接:函数(范围、元素、属性)
尝试使用$apply方法:
elem.bind('click',function(){
scope.$apply(function(){
scope.vModel=model.slice(0,20);
});
});
捕捉点击事件的最佳方法是使用angular ng-click指令:https://docs.angularjs.org/api/ng/directive/ngClick
相关文章:
- ng映射方向备选方案
- AngularJS UI路由器不能像ng路由器那样工作
- 角度:在ng重复上切换图像
- 正在使用$location.path(.)路由ng视图
- AngularJS:ng之后,重复$scope值未按预期更新
- ng打开空字符串
- 我应该使用Ng提交还是点击表格
- ng init中的表达式无法使用ng repeat
- ng更改事件不适用于Dropdown
- ng视图外的链接重定向到ng视图内的页面
- RubyonRails——构建交互式接口应该朝哪个方向发展
- 需要帮助谷歌地图方向面板在FancyBox中显示
- ng应用程序使脚本无限运行
- 角度的项目列表 ng 重复,ng 单击显示全宽描述
- ng隐藏和ng显示无法正常工作
- 从ng模板访问作用域
- ng按角度方向重复
- ng按角度方向单击
- 角度方向ng显示不工作
- 只允许向一个方向拖动ng-drag元素