本文整理匯總了TypeScript中ember.Controller類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Controller類的具體用法?TypeScript Controller怎麽用?TypeScript Controller使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Controller類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: model
import Ember from 'ember';
import DS from 'ember-data';
Ember.Route.extend({
model(): any {
return this.store.findAll('my-model');
}
});
Ember.Controller.extend({
actions: {
create(): any {
return this.store.createRecord('my-model');
}
}
});
Ember.DataAdapter.extend({
test() {
this.store.findRecord('my-model', 123);
}
});
示例2:
import Ember from 'ember';
export default Ember.Controller.extend({
// Just a very roundabout way of using some ES6 features
value: ((test = 'Test') => `${test} ${'Value'}`)()
});
示例3: beforeModel
import Ember from 'ember';
Ember.Route.extend({
beforeModel(transition: Ember.Transition) {
if (new Date() > new Date('January 1, 1980')) {
alert('Sorry, you need a time machine to enter this route.');
transition.abort();
}
}
});
Ember.Controller.extend({
previousTransition: null as Ember.Transition | null,
actions: {
login() {
// Log the user in, then reattempt previous transition if it exists.
let previousTransition = this.get('previousTransition');
if (previousTransition) {
this.set('previousTransition', null);
previousTransition.retry();
} else {
// Default back to homepage
this.transitionToRoute('index');
}
}
}
});