angularjs 模态窗口中的模型为空 [英] Model in a modal window in angularjs is empty

查看:28
本文介绍了angularjs 模态窗口中的模型为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在使用 angularjs ui bootstrap,并且我在模态窗口中有一个文本字段,当我尝试在警报窗口中打印它时它是空的.有什么原因吗?这是代码的plunker.

Hello I am using angularjs ui bootstrap and I have one text field in a modal window, which when I try to print it in alert window it is empty. Any reasons why? Here is a plunker of the code.

推荐答案

尝试更改

  • $scope.testField

进入

  • $scope.myModel.testField (或 user.firstName...)

如本视频中所述angular JS - 最佳实践 (29:19):

As mentioned in this video angular JS - best practice (29:19):

每当你有 ng-model 时,就必须在某个地方有一个点.如果你没有一个点,你就做错了."

"Whenever you have ng-model there's gotta be a dot in there somewhere. If you don't have a dot, you're doing it wrong."

查看更新的 plunker http://plnkr.co/edit/z1ABPEUB7Nxm1Kxey9iv?p=preview

See updated plunker http://plnkr.co/edit/z1ABPEUB7Nxm1Kxey9iv?p=preview

注意:很好地提醒了文章 Angular JS 中的嵌套作用域

NOTE: with a nice reminder of the video-minute from article Nested Scopes in Angular JS

这篇关于angularjs 模态窗口中的模型为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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