ng-change在文本输入上不起作用 [英] ng-change not working on a text input

查看:271
本文介绍了ng-change在文本输入上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是angular js的新手。在我的代码中,有一个从文本字段初始化的颜色选择器。用户更改了color的值,我希望将该颜色反映为跨度中文本的背景。它不起作用。

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>

柱塞- 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屋!

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