我是 Ember 的新手,作为学习的一部分,我试图从一个教程中设置登录表单,但它似乎不起作用。 错误:无效路径---这就是我在登录方法中遇到的错误
我想看看密码是否正确,然后连接登录模板,否则将用户踢到'/'。?
html文件
<script type="text/x-handlebars" data-template-name="login">
{{message}} <br>
E-Mail {{view Ember.TextField target="controller" valueBinding= controller.email}} <br />
Password {{view Ember.TextField target="controller" valueBinding= controller.password}} <br />
<button {{action login}}>Login</button>
</script>
<script type="text/x-handlebars" data-template-name="loggedin">
Welcome to Our Site !
</script>
JS文件
App.LoginController = Ember.ObjectController.extend({
email :null,
password :null,
message :null,
login : function() {
var loginCreds = this.getProperties('email','password');
if (loginCreds.password === 'admin') {
this.set('isAuthenticated',true);
console.log(isAuthenticated);
this.get('target').send('isAuthenticated');
}
else{
this.set('message','Invalid password');
this.set('isAuthenticated',false);
console.log(isAuthenticated);
this.get('target').send('isAuthenticated');
}
}
});
App.LoginRoute = Ember.Route.extend({
isAuthenticated : function(router) {
router.transitionTo('loggedin');
},
connectOutlets: function(router) {
if (!router.get('loginController.isAuthenticated')) {
router.transitionTo('/');
}
router.get('loginController').connectOutlet('loggedin');
},
});