单击按钮后,我需要将3个输入字段中的文本重置为空。当我点击“Speichern”按钮时,文本会保留在输入字段中,但我希望点击后这些输入字段为空。
<div class="cInputChangePWColor">
<div class="cClearFloat cInputSpace">
<input class="cInputWidth" placeholder="Altes Passwort" ng-model="passwordOld">
</div>
<div class="cClearFloat cInputSpace">
<input class="cInputWidth" placeholder="Neues Passwort" ng-model="passwordNew">
</div>
<div class="cClearFloat cInputSpace">
<input class="cInputWidth" placeholder="Passwort bestätigen" ng-model="passwordNewConfirmed">
</div>
<div class="cClearFloat cButtonPosition">
<button class="cButtonSpeichernSettings" ng-click="showAlertchangePassword(); setTextDefault()">Speichern</button>
<button class="cButtonAbbrechenSettings" ng-click="isShownchangePw = false; isShownSettings = false">Abbrechen</button>
</div>
</div>
我尝试过这样但是没有用。
$scope.setTextDefault = function() {
$scope.passwordOld == '';
$scope.passwordNew == '';
$scope.passwordNewConfirmed == '';
}
答案 0 :(得分:3)
将$scope.passwordOld == '';
更改为$scope.passwordOld = '';
答案 1 :(得分:2)
import { Component, ElementRef, AfterViewInit, ... } from '@angular/core';
declare var $: any;
@Component({
selector: 'modal',
templateUrl: './modal.html',
})
export class Modal implements AfterViewInit {
modalEl = null;
constructor(private _rootNode: ElementRef) {}
ngAfterViewInit() {
this.modalEl = $(this._rootNode.nativeElement).find('div.modal');
}
hasNgContent(selector:string) {
return $(this._rootNode.nativeElement).find(selector).length;
}
}
您也可以使用重置功能。您只需将DOM包装在$scope.reset = function(form) {
var fields = Object.keys(form).filter(function(key) {
return (key.indexOf('$') !== 0);
});
for (var i = 0; i < fields.length; i++) {
var name = fields[i];
var field = form[name];
field.$setViewValue(undefined);
field.$render();
}
form.$setPristine();
form.$setUntouched();
};
中并将Form
传递给重置函数。