wonderful world
wonderful world

Reputation: 11599

Integrating WinJS and Angular2

I'm trying to wrap a WinJS rating control in an Angular2 component. When I debug, I can see that WinJS.UI.processAll(); is being called and executed. But I don't see the rating control.

How can I make it work?

Dashboard.cshtml:

@{
    ViewBag.Title = "Dashboard";
}

<my-app></my-app>

<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 } from 'angular2';
import 'reflect-metadata';
import 'winjs';

@Component({
    selector: 'my-app'
})
@View({
    template: '<div data-win-control=\'WinJS.UI.Rating\' data-win-options=\'{averageRating: 3.4}\'></div>'
})
class MyAppComponent {
    constructor() {
    }

    onInit() {
        WinJS.UI.processAll();
    }
}

bootstrap(MyAppComponent);

Upvotes: 4

Views: 926

Answers (1)

Eric Martinez
Eric Martinez

Reputation: 31777

As requested by @wonderfulworld

First of all, according to Adding the Windows Library for JavaScript to your page you must add the css file to your html.

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/winjs/4.3.0/css/ui-light.min.css">

Second thing, from alpha37+ you must import and implement the lifecycle hook you're using, onInit in this case (see remove LifecycleEvent).

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

@Component({
    selector: 'my-app'
})
@View({
    template: '<div data-win-control=\'WinJS.UI.Rating\' data-win-options=\'{averageRating: 3.4}\'></div>'
})
class MyAppComponent implements OnInit {
    onInit() {
        WinJS.UI.processAll();
    }
}

And that would be all. Here's the plnkr.

Glad it helped ;)

Upvotes: 3

Related Questions