angularjs - 特殊字符不会从输入表单中显示在 AngularJS 中,例如 % & ? @
问题描述
我有一个 AngularJS 表单,它在输入框下方的代码片段中显示来自输入框的密码。但是当用户在密码中输入任何特殊字符时,密码将不再显示,甚至非特殊字符也不会显示。Chrome、Firefox 和 Internet Explorer 的结果相同。
表单脚本:
<script>
angular.module('tutorialApp', [])
.controller('TutorialController', ['$scope', function($scope) {
$scope.tutorial = {
ipno: '123.456.7.8',
sudouser: 'mysudouser1',
dbname: 'mydb1',
dbuser: 'mydbuser1',
dbpw: 'mydbpassword',
yourdomain: 'yourdomain.com',
your2nddomain: 'test.yourdomain.com',
name: 'name',
word: /^\s*\w*\s*$/
};
}]);
</script>
表单输入:
<label for="dbpw">Database password:</label>
<input type="text" name="dbpw" ng-model="tutorial.dbpw" ng-pattern="tutorial.word" id="dbpw">
代码片段:
<code>CREATE USER '<span class="frominput">{{tutorial.dbuser}}</span>'@'localhost' IDENTIFIED BY '<span class="frominput">{{tutorial.dbpw}}</span>';</code>
解决方案
您需要添加allowInvalid
. ng-model-options
添加这个input
-ng-model-options="{ allowInvalid: true }"
检查这个 - https://docs.angularjs.org/api/ng/directive/ngModelOptions
angular.module('tutorialApp', [])
.controller('TutorialController', ['$scope', function($scope) {
$scope.tutorial = {
ipno: '123.456.7.8',
sudouser: 'mysudouser1',
dbname: 'mydb1',
dbuser: 'mydbuser1',
dbpw: 'mydbpassword',
yourdomain: 'yourdomain.com',
your2nddomain: 'test.yourdomain.com',
name: 'name',
word: /^\s*\w*\s*$/
};
}]);
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="tutorialApp" ng-controller="TutorialController">
<label for="dbpw">Database password:</label>
<input type="text" name="dbpw" ng-model="tutorial.dbpw" ng-pattern="tutorial.word" id="dbpw" ng-model-options="{ allowInvalid: true}">
<br><br>
<code>CREATE USER '<span class="frominput">{{tutorial.dbuser}}</span>'@'localhost' IDENTIFIED BY '<span class="frominput">{{tutorial.dbpw}}</span>';</code>
</div>
推荐阅读
- javascript - D3(v5) 可折叠树与搜索
- azure-logic-apps - Azure 逻辑应用:For Each 循环中的 HTTP POST 显示未经授权的错误
- python - python scipy stats cdf beta-pert 计算返回 nan
- date - Flatline:如何计算两个日期之间的天数
- postgresql - Objection.js 渴望多对多关系问题
- excel - 如何在 iframe 中显示 xlsx 文件
- python - 从数组中的一个浮点数中查找值
- python - 元组中仅打印一个元素
- java - JScrollPanel,水平和垂直滚动不起作用
- ecmascript-5 - DocFx 预处理器上下文中的简单 API 调用