我試圖驗證email
地址,並相應地啓用或禁用操作按鈕。但它不起作用。我對emberjs
非常陌生,請幫助我嗎? Here is my TutorialEmber無法通過驗證電子郵件來啓用/禁用
HTML代碼(HBS):
<div class="jumbotron text-center">
<h1>Coming Soon</h1>
<br/><br/>
<p>Don't miss our launch date, request an invitation now.</p>
<div class="form-horizontal form-group form-group-lg row">
<div class="col-xs-10 col-xs-offset-1 col-sm-6 col-sm-offset-1 col-md-5 col-md-offset-2">
<input type="email" value=emailAddress class="form-control" placeholder="Please type your e-mail address." autofocus="autofocus"/>
</div>
<div class="col-xs-10 col-xs-offset-1 col-sm-offset-0 col-sm-4 col-md-3">
<button class="btn btn-primary btn-lg btn-block" disabled={{isDisabled}} {{action 'saveInvitation'}}>Request invitation</button>
</div>
</div>
<br/><br/>
</div>
控制器JS:
import Ember from 'ember';
export default Ember.Controller.extend({
emailAddress:'',
isValid: Ember.computed.match('emailAddress', /^[email protected]+\..+$/),
isDisabled: Ember.computed.not('isValid'),
actualEmailAddress: Ember.computed('emailAddress', function() {
console.log('actualEmailAddress function is called: ', this.get('emailAddress'));
}),
emailAddressChanged: Ember.observer('emailAddress', function() {
console.log('observer is called', this.get('emailAddress'));
}),
actions: {
saveInvitation() {
alert(`Saving of the following email address is in progress: ${this.get('emailAddress')}`);
this.set('responseMessage', `Thank you! We've just saved your email address: ${this.get('emailAddress')}`);
this.set('emailAddress', '');
}
}
});
當我輸入有效電子郵件,按鈕不能夠! 在此先感謝。
UPDATE:
在瀏覽器中我得到這個錯誤:
DEPRECATION: Usage of `router` is deprecated, use `_routerMicrolib` instead.
感謝您的詳細信息。我今天剛剛開始了'餘燼'。我正在關注這個教程。 – 3gwebtrain
很棒;用餘燼玩得開心:) – alptugd
我剛開始學習Ember。你能推薦一些好的教程嗎? – 3gwebtrain