End*_*ame 4 html javascript jquery input angularjs
我有这种情况:
有一些输入文字.当我填充输入时,我可以通过按钮隐藏它们.我需要的是,当输入隐藏所有内容时,键入清楚.因此,当我单击"显示"按钮时,输入必须为空.在有人问我之前我不能使用ngIf.
这是代码:
<div ng-controller="myCtrl">
<button ng-click="hideStuff()">Hide!</button>
<button ng-click="showStuff()">Show!</button>
<div ng-repeat="item in inputFileds">
<input placeholder="{{item.label}}" class="default" ng-hide="hidden" ng-class="{'fade': startFade, 'show': !startFade}" type="text" ng-model="item.value" />
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
和javascritp
var myApp = angular.module('myApp', []);
myApp.controller("myCtrl", function($scope, $timeout) {
$scope.hideStuff = function() {
$scope.startFade = true;
$timeout(function() {
$scope.hidden = true;
}, 700);
};
$scope.showStuff = function() {
$scope.startFade = false;
$timeout(function() {
$scope.hidden = false;
}, 700);
};
$scope.inputFileds = [{
"label": "input1",
"value": ""
}, {
"label": "input2",
"value": ""
}, {
"label": "input3",
"value": ""
}, {
"label": "input4",
"value": ""
}];
});
Run Code Online (Sandbox Code Playgroud)
您可以通过正确的设计避免此类问题!
为什么要将配置数据(标签)放入模型中?将它们分成2个对象,因为标签是静态的,但输入字段值不是.然后你可以很简单地重置模态.
$scope.model = {};
Run Code Online (Sandbox Code Playgroud)
就是这样 - 不需要重置每一个字段!