将占位符绑定到模型会导致ng-change在IE中加载时执行 [英] Binding the placeholder to the model causes ng-change to execute on load in IE

查看:46
本文介绍了将占位符绑定到模型会导致ng-change在IE中加载时执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用angularjs,如果我将输入的占位符绑定到其模型,则将文档加载到IE中时会触发change事件.这似乎不正确,并且在其他浏览器中也没有看到这种行为.

Using angularjs, if I bind the placeholder of an input to its model, the change event is fired when the document loads in IE. This does not appear to be correct and I'm not seeing this behavior in other browsers.

JS Fiddle

HTML:

<div ng-app="angularjs-starter" data-ng-controller="MainCtrl">
<div data-ui-view="viewMain">
    <input 
    placeholder="{{theValue}}" 
    data-ng-model="theValue" 
    data-ng-change="valueChanged(theValue)" />            
</div>

Javascript:

Javascript:

var app = angular.module('angularjs-starter', []);
app.controller('MainCtrl', function($scope) {  
    $scope.valueChanged = function(theValue) {
        alert("Value Change Called On Load in IE.");
    };
});

推荐答案

可以使用内置的

It's possible to use the built-in ng-attr-placeholder directive as well.

ng-attr-placeholder="{{theValue}}" 

这篇关于将占位符绑定到模型会导致ng-change在IE中加载时执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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