Igo*_*gor 3 ember.js typescript
我正在尝试将 RouterService 注入我的控制器:
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import RouterService from '@ember/routing/router-service';
export default class Search extends Controller.extend({
// anything which *must* be merged to prototype here
}) {
@service router!: RouterService;
@action
actionClick(){
this.router.transitionTo('protected.apk.detail')
}
}
// DO NOT DELETE: this is how TypeScript knows how to look up your controllers.
declare module '@ember/controller' {
interface Registry {
'search': Search;
}
}
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误:Error: Assertion Failed: Attempting to inject an unknown injection: 'service:router'
我猜这是因为没有 service:router,而是 router:main 。你能告诉我如何正确注入 RouterService 吗?该控制器位于我的引擎中。余烬版本:3.18.0
谢谢
服务底部的类型定义是一条线索。
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { Registry as Services } from '@ember/service';
export default class Search extends Controller {
@service router!: Services['router'];
@action
actionClick(){
this.router.transitionTo('protected.apk.detail')
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1233 次 |
| 最近记录: |