我正在學習平均堆棧開發和沿着視頻教程課程。一切都很順利,直到我嘗試匹配兩個密碼字段時遇到此錯誤。 「密碼」和「確認密碼」 我寫的確切代碼教程但我得到的命令行下面的錯誤(咕嘟咕嘟服務)
錯誤「$ ATTRS」不defind NO-民主基金
錯誤 「$ ATTRS」 不defind沒有民主基金
下面的代碼
export function CompareToDirective($parse) {
'ngInject'
return {
require: 'ngModel',
link: function (scope, elm, attrs, ngModel) {
var mainModel = $parse(attrs.compareTo);
var secondModel = $parse(attrs.ngModel);
scope.$watch(attrs.ngModel, function (newValue) {
ngModel.$setValidity($attrs.name, newValue === mainModel(scope));
});
scope.$watch(attrs.compareTo, function (newValue) {
ngModel.$setValidity($attrs.name, newValue === secondModel(scope));
});
}
}
}
編輯
這裏是我試圖驗證,以防萬一
<form name="register">
<div class="form-group">
<label>Email address</label>
<input type="email" class="form-control">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" name="pwd" ng-model="pwd">
</div>
<div class="form-group">
<label>Password Confirm</label>
<input type="password" class="form-control" compareTo="pwd" name="pwdConfirm" ng-model="pwdConfirm">
</div>
<span ng-show="register.pwdConfirm.$invalid">Passwords do not match</span>
<button type="submit" class="btn btn-default">Submit</button>
</form>
刪除「$」從$ ATTRS ..只是使用ATTRS –
你確定它不只是'attrs' ...這是你所擁有的在你的函數定義中。 – TripeHound
http://pasteboard.co/AG6q8O6OL.png 以下是教程中代碼的屏幕截圖。其中有「$ attrs」 當我從「attrs」刪除$ $ 錯誤去但仍然表單不起作用 –