我是Angular JS的新手,想要以登錄表單開始。我閱讀了一些在線資料,並決定放棄它。無法訪問Angular JS中的控制器
下面是我的代碼,當我點擊「登錄」時,沒有任何反應,我不確定我的html腳本是否與控制器通信,或者我在控制器中編寫了錯誤代碼。
<!DOCTYPE html>
<html data-ng-app="loginAuth">
\t <head>
\t \t <title>
\t \t </title>
\t </head>
\t <body>
\t
\t <h2>Angular Authentication</h2>
\t <div data-ng-controller="loginController">
\t \t <label>Username</label>
\t \t <input type="text" name="username" data-ng-model="login.username"/>
\t \t <br/>
\t \t
\t \t <label>Password</label>
\t \t <input type="password" name="password" data-ng-model="login.password"/> \t
\t \t <br/>
\t \t
\t \t <input type="button" ng-submit="login.submit(login.username, login.password)" value="Login"/>
\t \t <br/><br/>
\t \t {{login.message}}
\t </div>
\t
\t <script src="angular.min.js"></script>
\t
\t <script>
\t
\t 'use strict';
\t
\t angular.module('loginAuth')
\t .controller('loginController', function ($scope)
\t {
\t
\t function login.submit(username, password)
\t {
\t \t if (username === 'admin' && password === 'test99')
\t \t {
\t \t .then(onSuccess);
\t \t }
\t \t else
\t \t {
\t \t .catch(onError);
\t \t }
\t }
\t
\t function onSuccess()
\t {
\t \t login.message = 'Login Successful!';
\t }
\t function onError(reason)
\t {
\t \t login.message = reason.message;
\t }
\t });
\t
\t </script>
\t </body>
</html>
是否有人可以幫助我。
Thanks!這很有效,我看到我使用了ng-submit,而不是ng-click作爲按鈕事件。再次感謝你! – user1234