Angular2,它有一个WinJS组件,另一个Angular2组件不起作用

时间:2015-09-28 12:20:35

标签: angularjs winjs

正如您在以下代码中注意到的那样, dashboard.cshtml 有一个名为 dashboard-app angular2 组件。 信息中心应用 winjs 分配器控件来自 dashboard.html 。此控件具有另一个 contentara angular2 组件。

当我运行以下操作时,我在控制台中看不到任何错误。但我没有看到 contentarea 呈现。

我的期望是在内容区域中看到测试。我假设 bootstrap(MyAppComponent); (来自 app.js )应该连接整个应用程序,所以我应该在内容中看到 Testing 区域来自 contentarea 组件。

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>

1 个答案:

答案 0 :(得分:0)

添加指令,如下所示修复它:

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