路由无法读取未定义

时间:2016-11-03 17:21:14

标签: angular routing

导航到任何路线时遇到以下错误。 (这就是为什么我认为它与路由有关,但这只是猜测...)

VM8792:48 EXCEPTION: Uncaught (in promise): Error: Error in ./ContactComponent class ContactComponent_Host - inline template:0:0 caused by: Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at SafeSubscriber.eval [as _next] (eval at <anonymous> (http://localhost:8080/app.js:1674:1), <anonymous>:42:56)
    at SafeSubscriber.__tryOrUnsub (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:223:16)
    at SafeSubscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:172:22)
    at Subscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:125:26)
    at Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at RefCountSubscriber.Subscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:125:26)
    at RefCountSubscriber.Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at Subject.next (eval at <anonymous> (http://localhost:8080/vendor.js:44:1), <anonymous>:55:25)
    at ConnectableSubscriber.Subscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:125:26)
    at ConnectableSubscriber.Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at TextcontentService.load (eval at <anonymous> (http://localhost:8080/app.js:38:1), <anonymous>:161:35)
    at ContactComponent.ngOnInit (eval at <anonymous> (http://localhost:8080/app.js:1653:1), <anonymous>:25:33)
    at Wrapper_ContactComponent.detectChangesInInputProps (/AppModule/ContactComponent/wrapper.ngfactory.js:18:53)
    at _View_ContactComponent_Host0.detectChangesInternal (/AppModule/ContactComponent/host.ngfactory.js:30:30)
    at _View_ContactComponent_Host0.AppView.detectChanges (eval at <anonymous> (http://localhost:8080/vendor.js:3472:1), <anonymous>:233:14)
    at _View_ContactComponent_Host0.DebugAppView.detectChanges (eval at <anonymous> (http://localhost:8080/vendor.js:3472:1), <anonymous>:338:44)
    at ViewRef_.detectChanges (eval at <anonymous> (http://localhost:8080/vendor.js:2508:1), <anonymous>:136:20)
    at RouterOutlet.activate (eval at <anonymous> (http://localhost:8080/vendor.js:2708:1), <anonymous>:100:42)
    at ActivateRoutes.placeComponentIntoOutlet (eval at <anonymous> (http://localhost:8080/vendor.js:550:1), <anonymous>:802:16)
    at ActivateRoutes.activateRoutes (eval at <anonymous> (http://localhost:8080/vendor.js:550:1), <anonymous>:780:22)
    at eval (eval at <anonymous> (http://localhost:8080/vendor.js:550:1), <anonymous>:749:19)
    at Array.forEach (native)
    at ActivateRoutes.activateChildRoutes (eval at <anonymous> (http://localhost:8080/vendor.js:550:1), <anonymous>:748:29)
    at ActivateRoutes.activate (eval at <anonymous> (http://localhost:8080/vendor.js:550:1), <anonymous>:743:14)
    at eval (eval at <anonymous> (http://localhost:8080/vendor.js:550:1), <anonymous>:493:56)
    at SafeSubscriber.eval [as _next] (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:108:21)
    at SafeSubscriber.__tryOrSetError (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:232:16)
    at SafeSubscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:174:27)
    at Subscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:125:26)
    at Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at MergeMapSubscriber.notifyNext (eval at <anonymous> (http://localhost:8080/vendor.js:456:1), <anonymous>:133:30)
    at InnerSubscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:4368:1), <anonymous>:23:21)
    at InnerSubscriber.Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at MapSubscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:396:1), <anonymous>:83:26)
    at MapSubscriber.Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at ReduceSubscriber._complete (eval at <anonymous> (http://localhost:8080/vendor.js:829:1), <anonymous>:105:30)
    at ReduceSubscriber.Subscriber.complete (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:114:18)
    at MergeMapSubscriber._complete (eval at <anonymous> (http://localhost:8080/vendor.js:456:1), <anonymous>:125:30)
    at MergeMapSubscriber.Subscriber.complete (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:114:18)
    at ArrayObservable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:303:1), <anonymous>:116:24)
    at ArrayObservable.Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:56:27)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at MergeMapOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:456:1), <anonymous>:75:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at ReduceOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:829:1), <anonymous>:63:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at MapOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:396:1), <anonymous>:54:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at Object.subscribeToResult (eval at <anonymous> (http://localhost:8080/vendor.js:59:1), <anonymous>:21:27)
    at MergeMapSubscriber._innerSub (eval at <anonymous> (http://localhost:8080/vendor.js:456:1), <anonymous>:120:38)
    at MergeMapSubscriber._tryNext (eval at <anonymous> (http://localhost:8080/vendor.js:456:1), <anonymous>:117:14)
    at MergeMapSubscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:456:1), <anonymous>:100:18)
    at MergeMapSubscriber.Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at MergeMapSubscriber.notifyNext (eval at <anonymous> (http://localhost:8080/vendor.js:456:1), <anonymous>:133:30)
    at InnerSubscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:4368:1), <anonymous>:23:21)
    at InnerSubscriber.Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at EverySubscriber.notifyComplete (eval at <anonymous> (http://localhost:8080/vendor.js:2037:1), <anonymous>:47:26)
    at EverySubscriber._complete (eval at <anonymous> (http://localhost:8080/vendor.js:2037:1), <anonymous>:64:14)
    at EverySubscriber.Subscriber.complete (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:114:18)
    at MergeAllSubscriber._complete (eval at <anonymous> (http://localhost:8080/vendor.js:403:1), <anonymous>:94:30)
    at MergeAllSubscriber.Subscriber.complete (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:114:18)
    at MapSubscriber.Subscriber._complete (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:132:26)
    at MapSubscriber.Subscriber.complete (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:114:18)
    at ArrayObservable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:303:1), <anonymous>:116:24)
    at ArrayObservable.Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:56:27)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at MapOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:396:1), <anonymous>:54:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at MergeAllOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:403:1), <anonymous>:63:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at EveryOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:2037:1), <anonymous>:27:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at Object.subscribeToResult (eval at <anonymous> (http://localhost:8080/vendor.js:59:1), <anonymous>:21:27)
    at MergeMapSubscriber._innerSub (eval at <anonymous> (http://localhost:8080/vendor.js:456:1), <anonymous>:120:38)
    at MergeMapSubscriber._tryNext (eval at <anonymous> (http://localhost:8080/vendor.js:456:1), <anonymous>:117:14)
    at MergeMapSubscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:456:1), <anonymous>:100:18)
    at MergeMapSubscriber.Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at MapSubscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:396:1), <anonymous>:83:26)
    at MapSubscriber.Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at MapSubscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:396:1), <anonymous>:83:26)
    at MapSubscriber.Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at MapSubscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:396:1), <anonymous>:83:26)
    at MapSubscriber.Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at MergeMapSubscriber.notifyNext (eval at <anonymous> (http://localhost:8080/vendor.js:456:1), <anonymous>:133:30)
    at InnerSubscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:4368:1), <anonymous>:23:21)
    at InnerSubscriber.Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at Object.subscribeToResult (eval at <anonymous> (http://localhost:8080/vendor.js:59:1), <anonymous>:16:25)
    at MergeMapSubscriber._innerSub (eval at <anonymous> (http://localhost:8080/vendor.js:456:1), <anonymous>:120:38)
    at MergeMapSubscriber._tryNext (eval at <anonymous> (http://localhost:8080/vendor.js:456:1), <anonymous>:117:14)
    at MergeMapSubscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:456:1), <anonymous>:100:18)
    at MergeMapSubscriber.Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at CatchSubscriber.Subscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:125:26)
    at CatchSubscriber.Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at MapSubscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:396:1), <anonymous>:83:26)
    at MapSubscriber.Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at MapSubscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:396:1), <anonymous>:83:26)
    at MapSubscriber.Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at MapSubscriber._next (eval at <anonymous> (http://localhost:8080/vendor.js:396:1), <anonymous>:83:26)
    at MapSubscriber.Subscriber.next (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:89:18)
    at LastSubscriber._complete (eval at <anonymous> (http://localhost:8080/vendor.js:2881:1), <anonymous>:109:25)
    at LastSubscriber.Subscriber.complete (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:114:18)
    at MergeAllSubscriber._complete (eval at <anonymous> (http://localhost:8080/vendor.js:403:1), <anonymous>:94:30)
    at MergeAllSubscriber.Subscriber.complete (eval at <anonymous> (http://localhost:8080/vendor.js:29:1), <anonymous>:114:18)
    at ScalarObservable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:1995:1), <anonymous>:51:28)
    at ScalarObservable.Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:56:27)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at MergeAllOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:403:1), <anonymous>:63:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at LastOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:2881:1), <anonymous>:38:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at MapOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:396:1), <anonymous>:54:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at MapOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:396:1), <anonymous>:54:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at MapOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:396:1), <anonymous>:54:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at CatchOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:2002:1), <anonymous>:30:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at MergeMapOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:456:1), <anonymous>:75:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at MapOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:396:1), <anonymous>:54:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at MapOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:396:1), <anonymous>:54:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at MapOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:396:1), <anonymous>:54:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at MergeMapOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:456:1), <anonymous>:75:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at Observable._subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:114:28)
    at MergeMapOperator.call (eval at <anonymous> (http://localhost:8080/vendor.js:456:1), <anonymous>:75:23)
    at Observable.subscribe (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:53:22)
    at eval (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:87:38)
    at new ZoneAwarePromise (eval at <anonymous> (http://localhost:8080/polyfills.js:3536:1), <anonymous>:518:29)
    at Observable.forEach (eval at <anonymous> (http://localhost:8080/vendor.js:13:1), <anonymous>:86:16)
    at eval (eval at <anonymous> (http://localhost:8080/vendor.js:550:1), <anonymous>:477:18)
    at new ZoneAwarePromise (eval at <anonymous> (http://localhost:8080/polyfills.js:3536:1), <anonymous>:518:29)
    at Router.runNavigate (eval at <anonymous> (http://localhost:8080/vendor.js:550:1), <anonymous>:442:16)
    at eval (eval at <anonymous> (http://localhost:8080/vendor.js:550:1), <anonymous>:433:67)
    at ZoneDelegate.invoke (eval at <anonymous> (http://localhost:8080/polyfills.js:3536:1), <anonymous>:232:26)
    at Object.onInvoke (eval at <anonymous> (http://localhost:8080/vendor.js:1130:1), <anonymous>:238:37)
    at ZoneDelegate.invoke (eval at <anonymous> (http://localhost:8080/polyfills.js:3536:1), <anonymous>:231:32)
    at Zone.run (eval at <anonymous> (http://localhost:8080/polyfills.js:3536:1), <anonymous>:114:43)
    at eval (eval at <anonymous> (http://localhost:8080/polyfills.js:3536:1), <anonymous>:502:57)
    at ZoneDelegate.invokeTask (eval at <anonymous> (http://localhost:8080/polyfills.js:3536:1), <anonymous>:265:35)
    at Object.onInvokeTask (eval at <anonymous> (http://localhost:8080/vendor.js:1130:1), <anonymous>:229:37)
    at ZoneDelegate.invokeTask (eval at <anonymous> (http://localhost:8080/polyfills.js:3536:1), <anonymous>:264:40)
    at Zone.runTask (eval at <anonymous> (http://localhost:8080/polyfills.js:3536:1), <anonymous>:154:47)
    at drainMicroTaskQueue (eval at <anonymous> (http://localhost:8080/polyfills.js:3536:1), <anonymous>:401:35)
    at HTMLAnchorElement.ZoneTask.invoke (eval at <anonymous> (http://localhost:8080/polyfills.js:3536:1), <anonymous>:339:25)

以下是我的版本:

  "dependencies": {
    "@angular/common": "~2.1.1",
    "@angular/compiler": "~2.1.1",
    "@angular/core": "~2.1.1",
    "@angular/forms": "~2.1.1",
    "@angular/http": "~2.1.1",
    "@angular/platform-browser": "~2.1.1",
    "@angular/platform-browser-dynamic": "~2.1.1",
    "@angular/router": "~3.1.1",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.8",
    "angular2-bootstrap-pagination": "^1.0.6",
    "angular2-jwt": "^0.1.18",
    "bootstrap": "^4.0.0-alpha.4",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.12",
    "json-loader": "^0.5.4",
    "moment": "^2.14.1",
    "ng2-bootstrap": "^1.1.14",
    "ng2-charts": "^1.4.0",
    "zone.js": "^0.6.25"
  },
  "devDependencies": {
    "angular-cli": "1.0.0-beta.14",
    "angular2-template-loader": "^0.4.0",
    "copy-webpack-plugin": "^3.0.1",
    "css-loader": "^0.23.1",
    "extract-text-webpack-plugin": "^2.0.0-beta.4",
    "file-loader": "^0.8.5",
    "html-loader": "^0.4.3",
    "html-webpack-plugin": "^2.15.0",
    "jasmine-core": "^2.4.1",
    "node-sass": "^3.8.0",
    "null-loader": "^0.1.1",
    "phantomjs-prebuilt": "^2.1.7",
    "raw-loader": "^0.5.1",
    "rimraf": "^2.5.2",
    "style-loader": "^0.13.1",
    "ts-loader": "^0.8.1",
    "typescript": "^2.0.0",
    "typings": "^1.0.4",
    "webpack": "2.1.0-beta.22",
    "webpack-dev-server": "^2.1.0-beta.0",
    "webpack-merge": "^0.14.0"
  }

我正在使用它(在我的模块中的providers数组中)

{provide: LocationStrategy, useClass: HashLocationStrategy},

这就是我使用ROUTES的方式(在我的导入数组模块中):

RouterModule.forRoot(ROUTES)

我的所有路线都与此相似

 {
    path: 'contact',
    component: ContactComponent
  },

(有些人有额外的&#34; canActivate&#34;属性)

这在dev和prod模式下都会发生。

提前感谢您的帮助! 干杯, 圣拉斐尔

编辑:

这是我要求的ContactComponent的ngOnInit

ngOnInit() {
    this.textcontentService.textcontent.subscribe(latestText => {
      this.json = latestText;
    });
    this.textcontentService.load(Texttemplate.CONTACT);
}

这非常简单,只需订阅服务然后加载特定数据。我几乎在每个组件上都有这个,以前它从来都不是问题。

编辑2:

TextContentService绝对是麻烦的问题......

这项服务的想法是将文本/内容外包给json文件,然后通过此服务将它们注入到组件中。所以这个服务只是一个Subject / Observable组合。它导入一堆json文件并导出服务和ENUMS。

然后每个组件都可以使用相应的ENUM加载其文本。

json import:

var contactTemplate = require('!json!./../../../../public/textcontent/contact/contact.json');

主题/可观察

private _textcontentObserver: Subject<any> = new Subject();
public textcontent: Observable<any> = this._textcontentObserver.asObservable();

load函数只是一个很大的switch case语句。在这里联系部分:

case Texttemplate.CONTACT:
  this._textcontent = contactTemplate[this.language];
  break;

然后推送新内容:

this._textcontentObserver.next(this._textcontent);

好的为什么这个编辑2:如果我根本不使用这项服务,我可以毫无错误地导航到联系路线。但奇怪的是,这项服务一直在运作,现在已经破了。希望你们能帮助我! :)

0 个答案:

没有答案