使用
angularjs,如果我将输入的占位符绑定到其模型,则在IE中加载文档时会触发change事件.这似乎不正确,我在其他浏览器中没有看到这种行为.
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:
var app = angular.module('angularjs-starter',[]); app.controller('MainCtrl',function($scope) { $scope.valueChanged = function(theValue) { alert("Value Change Called On Load in IE."); }; });
解决方法
也可以使用内置的
ng-attr-placeholder
指令.
ng-attr-placeholder="{{theValue}}"