本文整理汇总了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');
}
}
}
});