尝试制作一个非常简单的(类似教程)NativeScript / Angular2应用程序。
我刚刚开始添加路由器和一个“基础”组件,其<page-router-outlet>
用于更改视图/导航。
添加此设置后,主要从此处复制:https://github.com/NativeScript/sample-Groceries 我现在收到一个错误:
JS: Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode.
JS: EXCEPTION: Uncaught (in promise): Error: No provider for ViewUtils!
JS: ORIGINAL STACKTRACE:
JS: Error: Uncaught (in promise): Error: No provider for ViewUtils!
JS: at resolvePromise (/data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:416:31)
JS: at /data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:393:13
JS: at ZoneDelegate.invoke (/data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:190:28)
JS: at Object.onInvoke (/data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/node_modules/@angular/core/bundles/core.umd.js:6206:41)
JS: at ZoneDelegate.invoke (/data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:189:34)
JS: at Zone.run (/data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:83:43)
JS: at /data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:449:57
JS: at ZoneDelegate.invokeTask (/data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:223:37)
JS: at Object.onInvokeTask (/data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/node_modules/@angular/core/bundles/core.umd.js:6197:41)
JS: at ZoneDelegate.invokeTask (/data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:222:42)
JS: Unhandled Promise rejection: No provider for ViewUtils! ; Zone: angular ; Task: Promise.then ; Value: Error: No provider for ViewUtils! Error: No provider for ViewUtils!
JS: at NoProviderError.Error (native)
JS: at NoProviderError.BaseError [as constructor] (/data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/node_modules/@angular/core/bundles/core.umd.js:1104:38)
JS: at NoProviderError.AbstractProviderError [as constructor] (/data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/node_modules/@angular/core/bundles/core.umd.js:1235:20)
JS: at new NoProviderError (/data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/node_modules/@angular/core/bundles/core.umd.js:1266:20)
JS: at ReflectiveInjector_._throwOrNull (/data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/node_modules/@angular/core/bundles/core.umd.js:2906:23)
JS: at ReflectiveInjector_._getByKeyDefault (/data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/node_modules/@angular/core/bundles/core.umd.js:2934:29)
JS: at ReflectiveInjector_._getByKey (/data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/node_modules/@angular/core/bundles/core.umd.js:2897:29)
JS: at ReflectiveInjector_.get (/data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/node_modules/@angular/core/bundles/core.umd.js:2706:25)
JS: at ComponentFactory.create (/data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/node_modules/@angular/core/bundles/core.umd.js:5803:31)
JS: at ViewContainerRef_.createComponent (/data/data/org.nativescript.wva/files/app/tns_modules/nativescript-angular/node_modules/@angular/core/bundles/core.umd.js:4857:49)
JS: Error: Uncaught (in promise): Error: No provider for ViewUtils!
不确定最有用的是什么,请原谅我这里有太多信息:
app.module.ts:
@NgModule({
imports: [
NativeScriptModule,
NativeScriptFormsModule,
NativeScriptRouterModule,
NativeScriptRouterModule.forRoot(routes)
],
declarations: [
BaseLayout,
Login,
Children
],
bootstrap: [
BaseLayout
]
})
export class AppModule {}
基layout.ts:
@Component({
moduleId: module.id,
selector: 'main',
providers: [
UserService,
{ provide: APP_CONFIG, useValue: AppConfig }
],
template: '<page-router-outlet></page-router-outlet>'
})
export class BaseLayout {}
login.ts
@Component({
moduleId: module.id,
selector: 'login',
providers: [
AuthService
],
templateUrl: './login.html',
styleUrls: [
'./login-common.css'
]
})
children.ts
@Component({
moduleId: module.id,
selector: 'children',
templateUrl: './children.html',
styleUrls: [
'./children-common.css'
]
})
感谢您的帮助。
答案 0 :(得分:1)
昨天我遇到了这个问题你需要删除node_modules
和platforms
目录然后更新package.json
"@angular/common": "~2.2.1",
"@angular/compiler": "~2.2.1",
"@angular/core": "~2.2.1",
"@angular/forms": "~2.2.1",
"@angular/http": "~2.2.1",
"@angular/platform-browser": "~2.2.1",
"@angular/platform-browser-dynamic": "~2.2.1",
"@angular/router": "~3.2.1",
"nativescript-angular": "^1.1.3"