ng-change 不适用于文本输入 [英] ng-change not working on a text input
本文介绍了ng-change 不适用于文本输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 angular js 的新手.在我的代码中有从文本字段初始化的颜色选择器.用户更改颜色的值,我希望该颜色反映为跨度中文本的背景.它不工作.缺少什么?
I am new to angular js. In my code there is color picker initialized from a text field. User changes the value of color and I want that color to be reflected as a background of a text in a span. It is not working. What is missing?
HTML:
<body ng-app="">
<input type="button" value="set color" ng-click="myStyle={color:'red'}">
<input type="button" value="clear" ng-click="myStyle={}">
<input type="text" name="abc" class="color" ng-change="myStyle={color:'green'}">
<br/>
<span ng-style="myStyle">Sample Text</span>
<pre>myStyle={{myStyle}}</pre>
</body>
Plunker - http://plnkr.co/edit/APrl9Y98Em0d6rxuzRDE?p=preview
但是,当我将其更改为 ng-click
时它可以工作.
However when I change it to ng-click
it works.
推荐答案
ng-change 需要 ng-model,
ng-change requires ng-model,
<input type="text" name="abc" class="color" ng-model="someName" ng-change="myStyle={color:'green'}">
这篇关于ng-change 不适用于文本输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文