加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 绑定在ng-if内停止输入

发布时间:2020-12-17 06:54:00 所属栏目:安全 来源:网络整理
导读:由于某种原因,绑定不适用于指令中ng-if块内的输入 所以这个,不起作用: app.directive 'foo',- restrict: 'E' scope: type:'=' template: "input ng-if="type === 'string'" ng-model='filterText' div {{filterText}} /div"foo type="'string'" / 它在指
由于某种原因,绑定不适用于指令中ng-if块内的输入

所以这个,不起作用:

app.directive 'foo',->
    restrict: 'E'
    scope:
       type:'='
    template: "<input ng-if="type === 'string'" ng-model='filterText'>
                  <div> {{filterText}} </div>"


<foo type="'string'" />

它在指令之外或没有ng-if时工作正常.如果没有帮助,用ng -w包含div内部的输入.这是一个错误吗?

jsbin link

解决方法

它是由ng-if引入一个新的范围和你的模型“没有点在其中”这一事实引起的.

这有效:

template: "<div ng-init='holder={}'> <input ng-if="type === 'string'" ng-model='holder.filterText'></div>
               <div> {{holder.filterText}}</div>"

请参阅https://docs.angularjs.org/api/ng/directive/ngIf中的指令信息,并注意文本“此指令创建新范围”.
对于“dot-in-model”,请参阅示例
Does my ng-model really need to have a dot to avoid child $scope problems?
要么
https://egghead.io/lessons/angularjs-the-dot基本上在读取值时,将正确读取范围原型,但在修改值时,它将被写入自己的范围.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读