Either I do not get the template, or my design is wrong.
Using angular2 -beta0, typescript
Basically, I created a very basic application with a root component - a router that controls the main views, and then on some pages I have an auxiliary router for managing the views on this component.
What I seem to be struggling with is how to structure things with communication between components. The application, as at the moment, is designed in such a way that it makes sense to me, the main types of routes have nothing in common, and in the subroutine representations they all have the same navigation and headers. It seems that the problem is with the presentation of the parent subview view. It seems that the child is in the router-output, he can not get dependent on the parent component. I looked at custom events, but they seem to work if attached to a template. The only other option seems to be a service, but to me it seems violated. Ideally, I want the parent component to monitor the state of the subcomponents.
Anyone like some example code ...
@Component({ selector: 'app' }) @View({ template: '<router-outlet></router-outlet>', directives: [ROUTER_DIRECTIVES] }) @RouteConfig([ { path: '/', as: 'Login', component: LoginForm }, { path: '/main/...', as: 'Main', component: Main} ]) class App { constructor(private _router: Router) { } } bootstrap(App, [ROUTER_PROVIDERS, provide(APP_BASE_HREF, { useValue: '/' })]); @Component({ selector: 'main' }) @View({ templateUrl: '/client/main/main.html', directives: [ROUTER_DIRECTIVES, NgClass, Menu, Main] }) @RouteConfig([ { path: '/', as: 'Clear', component: StateClear }, { path: '/offer', as: 'Offer', component: StateOffer } ]) export class Main { constructor(private _router: Router) { } } @Component({ selector: 'state-clear' }) @View({ templateUrl: '/client/bookings/state-clear.html' }) export class StateClear { constructor(main: Main) { } }
The error I get with DI is ...
EXCEPTION: Unable to resolve all parameters for StateClear (undefined). Make sure they all have valid type or annotations.
Error with the event, because I do not see how to listen outside the template.