Angularjs 文本框未被清除
我用的是角的 在我的控制器中,我有:Angularjs 文本框未被清除,angularjs,angularjs-directive,angularjs-scope,Angularjs,Angularjs Directive,Angularjs Scope,我用的是角的 在我的控制器中,我有: mainApp.controller('loginBoxController', ['$scope', '$state', 'mainWebService', function($scope, $state, mainWebService) { $scope.usernameText = ""; $scope.clear_fields = function() { $scope.usernameText = "";
mainApp.controller('loginBoxController', ['$scope', '$state', 'mainWebService', function($scope, $state, mainWebService) {
$scope.usernameText = "";
$scope.clear_fields = function() {
$scope.usernameText = "";
},
$scope.btnCancel = {
width:'45%',
height:'30px',
roundedCorners: 'all',
click : function(){
$scope.clear_fields();
}
};
}]);
在我的HTML中,我有
<div >
<input ng-jqxinput="txtusername" ng-model="usernameText" type="text" id="txtusernameID"/>
</div>
那么,我哪里做错了。请帮助我。请尝试此操作,创建新的单页应用程序并运行它。它会解决你的问题
<!DOCTYPE html>
<html>
<head>
<script data-require="angular.js@*" data-semver="1.3.0-beta.5" src="https://code.angularjs.org/1.3.0-beta.18/angular.js"></script>
<script>
var mainApp = angular.module('MyApp', []);
mainApp.controller('loginBoxController', ['$scope', function($scope) {
$scope.usernameText = "";
$scope.clear_fields = function() {
$scope.usernameText = "";
},
$scope.btnCancel = {
width:'45%',
height:'30px',
roundedCorners: 'all',
click : function(){
$scope.clear_fields();
}
};
}]);
</script>
</head>
<body ng-app="MyApp" ng-controller="loginBoxController">
<div >
<input ng-jqxinput="txtusername" ng-model="usernameText" type="text" id="txtusernameID"/>
<input type ="button" value="submit" ng-click="clear_fields()"/>
</div>
</body>
</html>
解决了我的问题
$scope.btnCancel = {
width:'45%',
height:'30px',
roundedCorners: 'all',
click : function(){
$scope.clear_fields();
$scope.$apply();
}
};
很抱歉,我忘了提到-我使用的是JQ小部件。你把$scope叫做哪里。清除字段?它必须按原样工作。是否可以设置plunker…尝试在$scope.clear\u字段后添加$scope.$apply;在click处理程序中,我通过单击按钮来调用clear_fields方法。
$scope.btnCancel = {
width:'45%',
height:'30px',
roundedCorners: 'all',
click : function(){
$scope.clear_fields();
$scope.$apply();
}
};