Integrating WinJS and Angular2 - winjs

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

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

Related

Angular 7 ngx-translate change run time transaltion without refresh page

Notes: I tired all questions & answers related to this topic.
I want to Translate Typescript variable Value without refresh page on change language Dropdown .
I trying To change the language-wise data change. I success to change to HTML Bind: value on dropdown value change but not update TypeScript Bind: value.
i use ngx-translate
I referer Links: but not success
angular-ngx-translate-usage-in-typescript
ngx-translate-in-ts-file-angular
ngx-translate-with-dynamic-text-on-ts-file
components.ts
import { Component, OnInit } from '#angular/core';
import { TranslateService } from '#ngx-translate/core';
#Component({
selector: 'app-translate',
templateUrl: './translate.component.html',
styleUrls: ['./translate.component.css']
})
export class TranslateComponent implements OnInit {
typeScriptvalue: string;
simpleProducts:any[]=[ {
name:'English',
id:'en'
},
{
name:'French',
id:'fr'
}];
constructor(private translate: TranslateService) {
this.typeScriptvalue = this.translate.instant('HOME.TITLE');
}
ngOnInit(): void {
}
changeevent(e)
{
console.log(e);
this.translate.use(e.value);
}
}
component.html
<label><b> HTML Bind</b></label> : <div>{{ 'HOME.TITLE' | translate }}</div> <br>
<label><b>TypeScript Bind</b></label> : <div>{{ typeScriptvalue }}</div> <br>
<label>
Change language : <div class="dx-field-value">
<dx-select-box [dataSource]="simpleProducts" displayExpr="name" valueExpr="id" (onValueChanged)="changeevent($event)"></dx-select-box>
</div>
</label>
After long research I have finally got the best solution.
You can reassign the Typescript variable on the subscriber method. use method
changeevent(e)
{
console.log(e);
this.translate.use(e.value).subscribe(data => {
this.typeScriptvalue = this.translate.instant('Home.Title');
});
}

Angular variable in component not rendering in template

Answer: I was using title: 'myTitle' instead of title = 'myTitle' ;(
I have just generated a new Angular app with one new component.
The problem is when i initialize a variable inside the class component and try to output it in the template using {{}} it is not showing variable's value.
In the main - App-Root Component it is written just like my code but there it is working :(
content.component.ts
import { Component } from '#angular/core';
#Component({
selector: 'app-content',
templateUrl: './content.component.html',
styleUrls: ['./content.component.sass']
})
export class ContentComponent {
title: 'Content'
}
content.component.html
<h3>{{title}}</h3>
This is how you should bind values :
In component.ts :
public title:any = 'Content';
in component.html :
<h1> {{title}} </h1>
Here is a working example : demo
Use the angular variable as below
title: string="Content"
For eg
Try this, I have created a sample MyComponent class as below.
import { Component, OnInit } from '#angular/core';
#Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
styleUrls: ['./my-component.component.css']
})
export class MyComponentComponent implements OnInit {
private myVariable:string="Hello World"
constructor() { }
ngOnInit() {
}
}
my-component.component.html
<p>
{{myVariable}}
</p>
Make sure add the above component in app.component.html which is the bootstrapping component as below
<app-my-component></app-my-component>
also in app.module as below in declartion section
declarations: [
AppComponent,
TopBarComponent,
ProductListComponent,
MyComponentComponent
],
bootstrap: [ AppComponent ]

Cannot register svg icon

I would like to register a new Material2 icon, I have this code:
import {Component, OnInit} from '#angular/core';
import {MatIconRegistry} from '#angular/material/icon';
import {DomSanitizer} from '#angular/platform-browser';
#Component({
selector: 'app-control-panel',
templateUrl: './control-panel.component.html',
styleUrls: ['./control-panel.component.scss']
})
export class ControlPanelComponent implements OnInit {
constructor(iconRegistry: MatIconRegistry, sanitizer: DomSanitizer) {
console.log('registering play button icon'); // << confirm
iconRegistry.addSvgIcon('play_button',
sanitizer.bypassSecurityTrustResourceUrl('assets/images/play-button.svg'));
}
ngOnInit() {
}
}
the log statement above is being hit. And I have this HTML
<button mat-raised-button color="accent">
<mat-icon>play_button</mat-icon>
Start Recording
</button>
if I use an existing icon it works, but if I use "play_button" it doesn't work.
Anyone know what might be going wrong?
<mat-icon> should set the svgIcon property. i.e.:
<mat-icon svgIcon="play_button"></mat-icon>
MatIconRegistry should be imported from #angular/material
Ensure that you import HttpClientModule in app.module.ts so the asset you're requesting can be downloaded.

Angular2 + ng2-Uploader UPLOAD_DIRECTIVES is not defined

Am trying to use ng2-uploader in my angular2 app , i'm trying to add a button click upload action in my view , i've tried to do like the documentations explains https://github.com/jkuri/ng2-uploader
component.ts
import {Component} from 'angular2/core';
import {UPLOAD_DIRECTIVES} from 'ng2-uploader/ng2-uploader';
#Component({
selector: 'demo-app',
templateUrl: 'app/demo.html',
directives: [UPLOAD_DIRECTIVES],
})
export class DemoApp {
uploadFile: any;
options: Object = {
url: 'http://localhost:10050/upload'
};
handleUpload(data): void {
if (data && data.response) {
data = JSON.parse(data.response);
this.uploadFile = data;
}
}
}
component.html
<a href="load" class="clas1"
[ng-file-select]="options"
(onUpload)="handleUpload($event)">
<div>
Response: {{ uploadFile | json }}
</div>
but i'm facing this error in my navigator :
Error: ReferenceError: UPLOAD_DIRECTIVES is not
defined(…)ZoneDelegate.invoke # angular2-polyfills.js:332Zone.run #
angular2-polyfills.js:227(anonymous function) #
angular2-polyfills.js:576ZoneDelegate.invokeTask #
angular2-polyfills.js:365Zone.runTask #
angular2-polyfills.js:263drainMicroTaskQueue #
angular2-polyfills.js:482ZoneTask.invoke # angular2-polyfills.js:434
therefore i have taken a look in the ng2-uploader component installed in the node and it looks like this :
///<reference path="../../node_modules/angular2/typings/browser.d.ts"/>
import {Ng2Uploader} from './src/services/ng2-uploader';
import {NgFileSelect} from './src/directives/ng-file-select';
import {NgFileDrop} from './src/directives/ng-file-drop';
export * from './src/services/ng2-uploader';
export * from './src/directives/ng-file-select';
export * from './src/directives/ng-file-drop';
export default {
directives: [NgFileSelect, NgFileDrop],
providers: [Ng2Uploader]
}
export const UPLOAD_DIRECTIVES: [any] = [NgFileSelect, NgFileDrop];
so it looks like everything is correct , anybody know how to repair this , , maybe i should add something to my boot.ts or my index.html , but what exactly ??
I would try the following SystemJS configuration in your main HTML file:
<script>
System.config({
map: {
'ng2-uploader': 'node_modules/ng2-uploader'
},
packages: {
(...)
'ng2-uploader': {
format: 'register',
defaultExtension: 'js'
}
}
});
(...)
</script>

Parameter in Ionic2 custom component not displayed

I am trying to build a simple component, just a div that prints a parameter but the parameter isn't been displayed:
test.html
<ion-content padding class="getting-started">
<my-component [test]="Something"></my-component>
</ion-content>
test.ts
import {Page} from 'ionic-framework/ionic';
import {MyComponent} from './myComponent';
#Page({
templateUrl: 'build/pages/test/test.html',
directives: [MyComponent]
})
export class TestPage {
constructor() {
}
}
myComponent.ts
import {Component,Input} from 'angular2/core';
#Component({
selector: 'my-component',
template: `
<div>Param: {{test}}</div>
`,
})
export class MyComponent {
#Input() test;
constructor() {
}
}
The result:
I can't figure it out what I am missing.
Your code is the same as the documentation (https://angular.io/docs/ts/latest/api/core/Input-var.html) except for the [test]="Something", have your tried to write test="Something" instead ?
I think [] syntax can take only variable of component.
I'm not sure, but try [test]="'Something'"

Resources