表单元素NG-模型变化范围分离指令手表不observered [英] form element ng-model change not observered in isolate scope directive watch

查看:86
本文介绍了表单元素NG-模型变化范围分离指令手表不observered的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这张贴拨弄之前,我对检查类似的问题。得到一些答案,但所有这些都无法形成元素。 http://jsfiddle.net/dgQAd/

Before posting this fiddle, i checked SO for similar question. Got few answer but all those were not form elements. http://jsfiddle.net/dgQAd/

我有以下问题:

1)文本框绑定到一个模型的uname ,但为onload文本框不显示值。为什么会这样?

1) The textbox is bound to a model uname, but onload the textbox is not displaying the value. why this is happening?

2),而寻找这个答案,我看到的东西像要求:ngModel ,并注入联函数内部控制,我该如何使用这里面注入控制器该指令的链接功能。

2)while searching for answers for this, i saw something like require:ngModel, and injecting a controller inside the linking function, how can i use this injected controller inside the linking function of the directive.

3)如何寻找父范围发生变化 NG-模型从分离范围指令的链接函数内。

3)How to look for the changes in the parent scope ng-model from inside a linking function of an isolate scope directive.

推荐答案

我已经能够得到NG-模型与分离范围工作唯一方法是使用相同的名称为分离作用域属性:范围:{的uname:= ngModel} 。你的手表$现在的工作。
欲了解更多关于这个又见 http://stackoverflow.com/a/14792601/215945

The only way I've been able to get ng-model to work with an isolate scope is to use the same name for the isolate scope property: scope:{ "uname":"=ngModel" }. Your $watch will now work. For more on this see also http://stackoverflow.com/a/14792601/215945

当一个指令要求是另一个指令的控制器,该控制器可作为第四选项链接功能。在你的小提琴,那是你叫什么 ngModel

When a directive requires another directive's controller, that controller is available as the 4th option to the linking function. In your fiddle, that is what you called ngModel:

link:function(scope,el,attrs,ngModel){

通常情况下,我preFER来命名这种ngModelCtrl提醒我,这是一个控制器。

Normally, I prefer to name this ngModelCtrl to remind me that it is a controller.

$观察仅用于与使用@语法分离作用域属性。

$observe is only used with isolate scope properties that use the '@' syntax.

这篇关于表单元素NG-模型变化范围分离指令手表不observered的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆