本文介绍了AngularJS:读ngModel的初始值$ viewValue从不同的指令。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读的初始值ngModel。$ viewValue从不同的指令。

I would like to read the initial value ngModel.$viewValue from different directive.

# coffee script
app.directive 'directive', ->
  return {
      require: '?ngModel',
      link: (scope, element, attrs, ngModelCtrl) ->
      ........
           console.log(ngModelCtrl.$viewValue) # does give NaN!

           ngModelCtrl.$setViewValue('something'); # only after setting reading does work
           console.log(ngModelCtrl.$viewValue)

我真的AP preciate任何帮助。

I really appreciate any help.

推荐答案

我只是固定它自己...愚蠢的:)

I just fixed it myself... stupid :)

    link: (scope, element, attrs, ngModelCtrl) ->

        scope.$watch(ngModelCtrl, ->
          console.log(ngModelCtrl.$viewValue)
        )

确实工作! yippieh!

does work! yippieh!

这篇关于AngularJS:读ngModel的初始值$ viewValue从不同的指令。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 14:20