Search code examples
angularjswinjs

Angular2 which has a WinJS component which has another Angular2 component not working


As you notice in the following code, the dashboard.cshtml has an angular2 component called dashboard-app. The dashboard-app has a winjs splitter control that comes from dashboard.html. This control has another contentara angular2 component.

When I run the following, I don't see any errors in the console. But I don't see the contentarea rendered.

My expectation is to see Testing in the content area. I assume bootstrap(MyAppComponent); (from app.js) should wire-up the whole app, so I should see Testing in the content area which comes from the contentarea component.

Output from Chrome:

enter image description here

Dashboard.cshtml

@{
    ViewBag.Title = "Dashboard";
}

<div class="container-fluid">
    <div class="row">
        <dashboard-app></dashboard-app>
    </div>
</div>

<script src="/jspm_packages/system.js"></script>
<script src="/config.js"></script>

<script>
    System.import('reflect-metadata')
        .then(function () {
            System.import('angular2')
                .then(function () {
                    System.import("/js/app");
                });
        });
</script>

App.js

import {Component, View, bootstrap,  OnInit} from 'angular2';
import 'reflect-metadata';
import 'winjs';
import '../js/content'

@Component({
    selector: 'dashboard-app'
})
@View({
    templateUrl: '../js/dashboard.html'
})
class MyAppComponent implements OnInit {
    constructor() {
    }

    onInit() {
        WinJS.UI.processAll().done(function () {
            var splitView = document.querySelector(".splitView").winControl;
            new WinJS.UI._WinKeyboard(splitView.paneElement); // Temporary workaround: Draw keyboard focus visuals on NavBarCommands
        });
    }
}

bootstrap(MyAppComponent);

content.js

import {Component, View, bootstrap,  OnInit} from 'angular2';
import 'reflect-metadata';

@Component({
    selector: 'contentarea'
})
@View({
    template: '<h3>Testing</h3>'
})
class ContentComponent {
    constructor() {
    }
}

dashboard.html

<div id="app">
    <div class="splitView" data-win-control="WinJS.UI.SplitView" data-win-options="{ openedDisplayMode : 'inline' }">
        <div>
            <div class="header">
                <button class="win-splitviewpanetoggle"
                        data-win-control="WinJS.UI.SplitViewPaneToggle"
                        data-win-options="{ splitView: select('.splitView') }">
                </button>
                <div class="title">SplitView Pane area</div>
            </div>
            <div class="nav-commands">
                <div data-win-control="WinJS.UI.SplitViewCommand" data-win-options="{ label: 'Home', icon: 'home'}"></div>
                <div data-win-control="WinJS.UI.SplitViewCommand" data-win-options="{ label: 'Favorite', icon: 'favorite'}"></div>
                <div data-win-control="WinJS.UI.SplitViewCommand" data-win-options="{ label: 'Settings', icon: 'settings'}"></div>
            </div>
        </div>
        <div class="contenttext">
            <contentarea></contentarea>
        </div>
    </div>
</div>

Solution

  • Adding directives like below fixed it:

    @Component({
        selector: 'dashboard-app'
    })
    @View({
        templateUrl: '../js/dashboard.html'
        directives: [ ContentComponent ]
    })