I am creating an application using AngurarJS 2, where I created a parent component "LayoutComponent" and various child components are called using @RouteConfig
. As below:
@RouteConfig([
{ path: '/dashboard', component: DashboardComponent, name: 'Dashboard', useAsDefault:true, data:{page:this.page} },
{ path: '/projects', component: ProjectListComponent, name: 'Project.list' },
{ path: '/project/:id', component: ProjectDetailComponent, name: 'Project.detail' },
{ path: '/project/add', component: ProjectAddComponent, name: 'Project.add' },
// { path: '/login', component: UserLoginComponent, name: 'User.login' },
{ path: '/logout', component: UserLogoutComponent, name: 'User.logout' },
{ path: '/users', component: UserListComponent, name: 'User.list' },
{ path: '/user/profile', component: UserProfileComponent, name: 'User.profile' },
{ path: '/user/:id', component: UserDetailComponent, name: 'User.detail' },
{ path: '/calendar', component: CalendarMainComponent, name: 'Calendar.main' },
{ path: '/emails', component: EmailListComponent, name: 'Email.list' },
// { path: '/user/register', component: UserRegisterComponent, name: 'User.register' },
])
I am using a layout template in LayoutComponent as template. I placed a tag <router-outlet></router-outlet>
in layout template where all child components render their views. Now I want to update some value from child component to layout component's view (e.g. "title"). When we call child components by using directives
then we can pass objects as inputs
in child components and when we make any change in that object within child component, the changes reflects to parent component and related view reflects.
But I am not able to do this when calling child component using @RouteConfig
. So I need help in this regard.
Any suggestion would be appreciated.
I want to tell that I tried to solve my problem by using a shared service object as bellow:
I created a service PageService
and injected it into parent component.
I passed it in constructor of LayoutComponent and assign it as component's page
property.
I used this "page" property in component's template to show value.
Now when I am updating value of service object's properties, I am getting change detection exception which stops further execution of script:
EXCEPTION: Expression '{{page.brdcrmb.title}} in LayoutComponent@223:37' has changed after it was checked