路径中的ember表单返回undefined

时间:2016-06-08 20:01:52

标签: javascript html ember.js ember-cli web-frontend

我对Ember很新。当我单击“提交”时,控制台显示this.getProperties返回未定义的电子邮件和密码输入。我不确定这里缺少什么。登录是一条路线。

login.hbs:

<div class="login">
    <div class="login-info">
      <b>LOGIN TO PROCEED.</b>
    </div>
    <div class="form">
      <form {{action 'authenticate'}} on='submit'>
          <label for="email"><small>EMAIL</small></label>
          <br>
          {{input value=email placeholder='Enter Email' class='form-control' type='text'}}
          <br>
          <label for="password"><small>PASSWORD</small></label>
          <br>
          {{input value=password placeholder='Enter Password' class='form-control' type='password'}}
          <br>
          <div class="login-button">
              <button type="submit">
              Login 
          </button>
          </div>
      </form>
   </div>
</div>

login.js

import Ember from 'ember';

export default Ember.Route.extend({
    session: Ember.inject.service('session'),
    actions: {
        authenticate() {
            let {email, password} = this.getProperties('email','password');
            Ember.Logger.info("email: ",email," password: ",password);\\this shows undefined for both email and password
            this.get('session').authenticate('authenticator:oauth2', email, password).then(() => {
                Ember.Logger.info("login successful");
            }, (err) => {
                Ember.Logger.info("login unsuccessful. message: ",err.errors);
            });
        }
    }
});

1 个答案:

答案 0 :(得分:4)

您在模板中使用的属性实际上是控制器的一部分,而不是路径。因此,如果您尝试在路线中记录{{1}},则应该能够获得正确的值。