如何使用HashLocationStrategy路由器在angular2-beta.20在dart? [英] How to use HashLocationStrategy for router in angular2-beta.20 in dart?
问题描述
我试图使用路由器在angular2-beta.20在Dart与HashLocationStrategy。
但我找不到任何文档,除了
此链接到angular2-beta.15 docs ,这是不完整的。
该示例显示了TypeScript导入,而不是Dart。
所以我试图导入 package:angular2 / router.dart
,但是Dart Analyzer一直抱怨找不到 LocationStrategy
和 HashLocationStrategy
t知道,如何写入导入完全,因为顶层提供功能,如上例中似乎不存在。
提供(LocationStrategy,{useClass:HashLocationStrategy})
p>经过一些研究,我发现了以下内容:
-
LocationStrategy
HashLocationStrategy
现在是
包:angular2 / platform / common.dart
的一部分,而不是<$ c $ bootstrap() c> - method是平台特定的,因此我们需要导入 -
我们需要导入
package:angular2 / router.dart
,以在<$ c $中提供ROUTER_PROVIDERS
c> bootstrap()方法。
package:angular2 / platform / browser.dart
。 文件初始化:
//需要导入bootstrap方法
import'package:angular2 / platform / browser。镖';
//需要导入LocationStrategy和HashLocationStrategy
import'package:angular2 / platform / common.dart';
// Provider类需要
import'package:angular2 / angular2.dart';
//需要导入ROUTER_PROVIDERS
import'package:angular2 / router.dart';
//将您的app_component导入为angular2的根组件
import'app_component.dart';
void main(){
bootstrap(AppComponent,[
ROUTER_PROVIDERS,
const Provider(LocationStrategy,useClass:HashLocationStrategy)
]
}
希望这有助于某人! :)
I tried to use the router in angular2-beta.20 in Dart with the HashLocationStrategy. But I couldn't find any docs, except for this link to angular2-beta.15 docs, which are incomplete. The example shows TypeScript imports instead of Dart ones.
So I tried to import package:angular2/router.dart
, but the Dart Analyzer keeps complaining that it can not find LocationStrategy
and HashLocationStrategy
Also I don't know, how to write the import exactly, because a top-level provide function, as in the example above, seems non existent.
provide(LocationStrategy, {useClass: HashLocationStrategy})
After some research I found the following:
LocationStrategy
andHashLocationStrategy
are now part ofpackage:angular2/platform/common.dart
instead ofpackage:angular2/router.dart
.The
bootstrap()
- method is platform specific, so we need to importpackage:angular2/platform/browser.dart
.We need to import
package:angular2/router.dart
to haveROUTER_PROVIDERS
available inbootstrap()
method.
Here is a working code example for the dart file initializing :
// needed to import "bootstrap" method
import 'package:angular2/platform/browser.dart';
// needed to import LocationStrategy and HashLocationStrategy
import 'package:angular2/platform/common.dart';
// needed for Provider class
import 'package:angular2/angular2.dart';
// needed to import ROUTER_PROVIDERS
import 'package:angular2/router.dart';
// import your app_component as root component for angular2
import 'app_component.dart';
void main() {
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
const Provider(LocationStrategy, useClass: HashLocationStrategy)
]);
}
Hope this helps somebody! :)
这篇关于如何使用HashLocationStrategy路由器在angular2-beta.20在dart?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!