4

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);
3

1 Answer 1

3

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 ;)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.