2015-04-18 80 views
0

我試圖在註冊表單上創建提交操作。這裏是我的註冊車把:表單提交操作錯誤emberjs

<form class="form-signin" {{action "register" on="submit"}}> 
    {{input class="form-control" value=username type="text" placeholder="Username"}} 
    {{input class="form-control" value=password type="password" placeholder="Password" }} 
    <button class="btn btn-lg btn-primary btn-block" type="submit">Register</button> 
    </form> 

這裏路由器:

import Ember from 'ember'; 
import config from './config/environment'; 

var Router = Ember.Router.extend({ 
    location: config.locationType 
}); 

Router.map(function() { 
    this.resource('register', {path: '/register'}); 
}); 

export default Router; 

,這裏是我的註冊控制器:

import Ember from 'ember'; 

export default Ember.Controller.extend({ 
    register: function(){ 
     return 'hello'; 
    } 
}); 

當我提交表單我得到這個錯誤:

Uncaught Error: Nothing handled the action 'register'. If you did handle the action, this error can be caused by returning true from an action handler in a controller, causing the action to bubble. 

我是什麼做錯了?

回答

1

我錯過了控制器中的action屬性。它應該看起來像這樣:

import'Ember from'ember';

export default Ember.Controller.extend({ 
    actions: { 
     register: function(){ 
      alert('hey'); 
     } 
    } 
});