从路由 ember 获取表单值

Get form values from route ember

我的 ember 应用程序中有一个表单,该表单有一个带有操作的路线。我想获取我的电子邮件和密码值并对它们进行处理。

但是,我无法使用 this.get('email') 获取值;我认为这会起作用。我如何获取这些值并在我的操作中使用它们?目前它只是将它们设置为空。

这是我的模板。

<div class='page-header'>
  <h1>Login</h1>
</div>
{{input
  type='text'
  class='form-control'
  value=email
  placeholder='email'
}}
{{input
  type='password'
  class='form-control'
  value=password
  placeholder='password'
}}
<button
  class='btn btn-default'
  {{action 'login'}}
>
  Login In
</button>

这是我的路线和行动。

export default Ember.Route.extend({
  firebaseApp: Ember.inject.service(),
  actions: {
    login() {
      const auth = this.get('firebaseApp').auth();
      let email = this.get('email') || '';
      let password = this.get('password') || '';
      auth.signInWithEmailAndPassword(email, password)
      .then(() => {
        console.log("signed in this works");
      })
      .catch(function (error) {
        console.log(error);
      });
    }
  }
});

当您在 Route 中使用 this.get() 时,this 就是 Route。当你在像 {{input value=password}} 这样的模板中使用表达式时,变量在控制器中。

Route 开始,您需要以这种方式访问​​这些变量: this.controller.get('password')

希望对您有所帮助。