问题描述
下面是我的plnkr:<一href=\"http://plnkr.co/edit/n8cRXwIpHJw3jUpL8PX5?p=$p$pview\">http://plnkr.co/edit/n8cRXwIpHJw3jUpL8PX5?p=$p$pview你必须点击一个li元素上的形式出现。输入一个随机字符串并点击添加通知。取而代之的是textarea的文字,你会得到不确定的。
Here is my plnkr: http://plnkr.co/edit/n8cRXwIpHJw3jUpL8PX5?p=preview You have to click on a li element and the form will appear. Enter a random string and hit 'add notice'. Instead of the textarea text you will get undefined.
标记:
<ul>
<li ng-repeat="ticket in tickets" ng-click="select(ticket)">
{{ ticket.text }}
</li>
</ul>
<div ui-if="selectedTicket != null">
<form ng-submit="createNotice(selectedTicket)">
<textarea ng-model="noticeText"></textarea>
<button type="submit">add notice</button>
</form>
</div>
JS部分:
$scope.createNotice = function(ticket){
alert($scope.noticeText);
}
返回'不确定'。我注意到,使用的用户界面,如果角UI时,这不起作用。任何想法,为什么不起作用?如何解决呢?
returns 'undefined'. I noticed that this does not work when using ui-if of angular-ui. Any ideas why this does not work? How to fix it?
推荐答案
您的问题在于用户界面,如果一部分。似乎角UI创建该指令中的任何一个新的范围,所以为了访问父范围,你必须做这样的事情:
Your problem lies in the ui-if part. It seems that angular-ui creates a new scope for anything within that directive so in order to access the parent scope, you must do something like this:
<textarea ng-model="$parent.noticeText"></textarea>
而不是
<textarea ng-model="noticeText"></textarea>
这篇关于不能得到angularjs textarea的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!