我在使用setPristine和我的表单时遇到错误。 错误是:
http://errors.angularjs.org/1.4.6/$injector/unpr?p0=%24setPristineProvider%20%3C-%20%24setPristine%20%3C-%20mainController
我的控制员:
"use strict";
var mainController = ['$scope', '$route', '$location', "$document", "$timeout", "modalService", "$setPristine",
function ($scope, $route, $location, $document, $timeout, modalService, $setPristine) {
$scope.$on('$routeChangeSuccess', function(newVal, oldVal) {
if (oldVal !== newVal) {
$scope.routeClassName = $route.current.className;
}
});
//config actions
$scope.changePasswrod = function ( data ) {
console.log( "change password called", data ); //i am getting data here.
$scope.formResetPassword.$setPristine();
}
}];
angular
.module('tcpApp')
.controller('mainController', mainController);
我的表格:
<form ng-submit="changePasswrod( changePass )" class="configForm resetPassword" name="formResetPassword" novalidate>
<a ng-click='hideModal()' class="configPopClose" ng-href=""><img src="images/configCloaseIcon.png" alt=""></a>
<h2>Change Password</h2>
<span class="indication"> * Indicates require fields</span>
<label for="userId" class="configUserId">
<input
type="text"
name="userId"
ng-model="changePass.userId"
placeholder="User Id"
required > <sup>*</sup>
</label>
<span class="errorWrap">
<span
ng-show="formResetPassword.userId.$dirty &&
formResetPassword.userId.$invalid"
class="error">
User Name Required
</span>
</span>
<label for="oldPassword" class="configOldPass">
<input type="password"
name="oldPassword"
placeholder="Old Password"
ng-model="changePass.oldPassword"
ng-pattern="/^[^\s]+$/"
required > <sup>*</sup>
</label>
<span class="errorWrap">
<span
ng-show="formResetPassword.oldPassword.$dirty &&
formResetPassword.oldPassword.$invalid"
class="error">
Please provide the old password
</span>
</span>
<label for="newPassword" class="configNewPass">
<input
type="password"
name="newPassword"
placeholder="New Password"
ng-model="changePass.newPassword"
ng-pattern="/^[^\s]+$/"
required > <sup>*</sup>
</label>
<span class="errorWrap">
<span
ng-show="formResetPassword.newPassword.$dirty && formResetPassword.newPassword.$invalid"
class="error">
Please provide new Password
</span>
</span>
<label for="reEnterNewPassword" class="configReEnter">
<input
type="password"
name="newPasswordConf"
placeholder="Re-Enter New Password"
ng-model="changePass.newPasswordConf"
required > <sup>*</sup>
</label>
<span class="errorWrap">
<span
ng-show="formResetPassword.newPasswordConf.$dirty &&
(changePass.newPassword != changePass.newPasswordConf || !formResetPassword.newPasswordConf.$valid)"
class="error">
Password Not Matching;
</span>
</span>
<span class="configBtnHolder">
<button
class="applyBtn configBtn"
type="submit"
id="stayChangePass"
ng-disabled="formResetPassword.$invalid"
>
Stay on Dashboard
</button>
<button
class="cancelBtn configBtn"
type="submit"
id="exitChangePass"
ng-disabled="formResetPassword.$invalid">
Exit Dashboard
</button>
</span>
</form>
如何解决这个问题?
答案 0 :(得分:1)
您不必在控制器中注入$setPristine
。从依赖注入列表中删除它,它应该可以正常工作。