I have the 3 components shown below:
news-feed.component
user-activity-item.component
user-activity-list.component
Both user-activity components are in a sub directory of news-feed component. Also, the user-activity item, is just a member of the user-activity-list.
Everything with this works, until I add the component selector cg-user-activity-list to the news-feed.component.html file.
Once I add that line, the route that I navigate to, shows the text in the news-feed.component.html, but the activity list never shows. Also, for some reason, the route in the URL bar quickly shows, like it successfully made it to the page, then goes back to the previous route (but stays on the page I intended).
I'm pretty new to Angular2, so I'm hoping that someone will immediately spot my mistake, but I've been looking at this a few hours, and haven't been able to see the problem.
Here's my files:
news-feed.component.ts
import { Component, OnInit } from '@angular/core';
import { UserActivityListComponent } from './user-activity-list/user-activity-list.component';
@Component({
selector: 'cg-news-feed',
templateUrl: './news-feed.component.html',
styleUrls: ['./news-feed.component.css']
})
export class NewsFeedComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
news-feed.component.html
<div class="pure-u-1">
Activity Test Text
<cg-user-activity-list></cg-user-activity-list>
</div>
user-activity.item.component.ts
import { Component, OnInit, Input } from '@angular/core';
import { UserActivity } from '../user-activity';
@Component({
selector: 'cg-user-activity-item',
templateUrl: './user-activity-item.component.html'
})
export class UserActivityItemComponent implements OnInit {
@Input() userActivity: UserActivity;
constructor() { }
ngOnInit() {
}
}
user-activity.item.component.html
<div class="pure-u-1">
testing user activity item component
<h4>{{userActivity.name}}</h4>
<p>{{userActivity.id}}</p>
</div>
user-activity.list.component.ts
import { Component, OnInit } from '@angular/core';
import { UserActivity } from '../user-activity';
//import { UserActivityItemComponent } from './user-activity-item.component';
@Component({
selector: 'cg-user-activity-list',
templateUrl: './user-activity-list.component.html'
})
export class UserActivityListComponent implements OnInit {
userActivities: UserActivity[] = [];
userActivity = new UserActivity('John', '25');
constructor() { }
ngOnInit() {
}
}
user-activity.list.component.html
<div class="pure-u-1">
testing user activity list component
<cg-user-activity-item> [userActivity]="userActivity" </cg-user-activity-item>
</div>
If I need to post more information on the project, I can, but it's fairly large, so I wasn't 100% sure what I'd need to post for someone to see the problem.
Additional Info.
Console error below
EXCEPTION: Uncaught (in promise): Error: Error in ./UserActivityItemComponent class UserActivityItemComponent - inline template:2:8 caused by: Cannot read property 'name' of undefined TypeError: Cannot read property 'name' of undefined at _View_UserActivityItemComponent0.detectChangesInternal (/AppModule/UserActivityItemComponent/component.ngfactory.js:51:66) at _View_UserActivityItemComponent0.AppView.detectChanges (http://localhost:4200/main.bundle.js:56495:14) at _View_UserActivityItemComponent0.DebugAppView.detectChanges (http://localhost:4200/main.bundle.js:56600:44) at _View_UserActivityListComponent0.AppView.detectViewChildrenChanges (http://localhost:4200/main.bundle.js:56521:19) at _View_UserActivityListComponent0.detectChangesInternal (/AppModule/UserActivityListComponent/component.ngfactory.js:52:8) at _View_UserActivityListComponent0.AppView.detectChanges (http://localhost:4200/main.bundle.js:56495:14) at _View_UserActivityListComponent0.DebugAppView.detectChanges (http://localhost:4200/main.bundle.js:56600:44) at _View_NewsFeedComponent0.AppView.detectViewChildrenChanges (http://localhost:4200/main.bundle.js:56521:19) at _View_NewsFeedComponent0.detectChangesInternal (/AppModule/NewsFeedComponent/component.ngfactory.js:61:8) at _View_NewsFeedComponent0.AppView.detectChanges (http://localhost:4200/main.bundle.js:56495:14)