我正在尝试在注册表单上创建提交操作。这是我的登记把手:
<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.
我做错了什么?
答案 0 :(得分:1)
我错过了控制器中的action属性。它应该是这样的:
从'ember'导入Ember;
export default Ember.Controller.extend({
actions: {
register: function(){
alert('hey');
}
}
});