You might want to try DynamicComponentLoader. Disclaimer, I have not used this with Angular2 Alpha. However, my approach was to detect screen resolution and dynamically load the component into the main template. For smaller devices, I downloaded the tab layout and for a larger sensitive grid. You could learn something like ng2-responsive for more reliable detection of permissions and device types.
In Angular2 Alpha (sorry example)
Plunger example
template:
<div>
<div #location></div>
</div>
component method:
setLayout(pSize:string) {
this.removeAll();
if(pSize === 'xs') {
console.log('loading layout ' + pSize);
this._dcl.loadNextToLocation(TabbedLayout, this._e).then((ref) => {
ref.instance._ref = ref;
this._children = ref;
});
} else {
console.log('loading grid ' + pSize);
this._dcl.loadNextToLocation(GridLayout, this._e).then((ref) => {
ref.instance._ref = ref;
this._children = ref;
});
}
}
: ( - ng2-responseive )
import {Injectable} from '@angular/core';
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/fromEvent';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/pluck';
import 'rxjs/add/operator/distinctUntilChanged';
@Injectable()
export class ResizeSvc {
width$: Observable<number>;
height$: Observable<number>;
layout$: Observable<string>;
constructor () {
let windowSize$ = new BehaviorSubject(this.getWindowSize());
this.width$ = windowSize$.pluck('width').distinctUntilChanged();
this.height$ = windowSize$.pluck('height').distinctUntilChanged();
this.layout$ = windowSize$.pluck('layout').distinctUntilChanged();
Observable.fromEvent(window, 'resize')
.map(this.getWindowSize)
.subscribe(windowSize$);
}
getWindowSize() {
var size = 'na';
if(window.innerWidth < 768) {
size = 'xs';
} else if (window.innerWidth < 992) {
size = 'sm';
} else if(window.innerWidth < 1200) {
size = 'md'
} else {
size = 'lg';
}
return {
height: window.innerHeight,
width: window.innerWidth,
layout: size
};
}
}