ng-class in Angular2

According to the NgClass API docs, Angular 2 will accept a string, an Array, or an Object/map as the expression to NgClass. Or, of course, you could specify a function that returns one of those. import {Component, CORE_DIRECTIVES} from ‘angular2/angular2’ @Component({ selector: ‘my-app’, directives: [CORE_DIRECTIVES], template: ` <div> <h2>{{title}}</h2> <div ngClass=”gray-border purple”>string of classes</div> <div … Read more

Visual Studio 2015 RC Typescript experimental decorators error

Visual Studio 2015 supports tsconfig files starting with Typescript version 1.8. Create tsconfig.json file at the root of your project and add experimentalDecorators compiler option. Example: { “compileOnSave”: true, “compilerOptions”: { “module”: “commonjs”, “sourceMap”: true, “experimentalDecorators”: true } } For older versions: https://github.com/Microsoft/TypeScript/issues/3934 If you have a project file, tsconfig will not be honored. the … Read more

How to enble/disable a button in TypeScript 1.5?

There should be a cleaner way to do this: var element = <HTMLInputElement> document.getElementById(“btnExcel”); element.disabled = true; Or if you prefer a one liner: (<HTMLInputElement> document.getElementById(“btnExcel”)).disabled = true; It seems getElementById and the like should be a generic method and accept a type parameter. That said, a generic method wouldn’t give you anything that typecasting … Read more

VSCode: Is it possible to suppress experimental decorator warnings

I was having this same error. I added the following tsconfig.json file to my project root, restarted VSCode and it finally went away: { “compilerOptions”: { “emitDecoratorMetadata”: true, “experimentalDecorators”: true, “module”: “amd”, “target”: “ES6″ } } UPDATE: I’ve noticed that sometimes VS Code will not suppress this warning until you add a “files” array in … Read more

Using namespace spread over multiple module files in TypeScript

Use re-exporting to create an external module that groups and exposes types from other modules: // Classes/Animals.ts export * from ‘.\Animals\Mammals’; export * from ‘.\Animals\Reptiles’; Then import the types from the new module as usual: // app.ts import * as Animals from ‘.\Classes\Animals’ let dog: Animals.Dog; let snake: Animals.Snake; Or // app.ts import { Dog, … Read more

Angular2 + Jspm.io : reflect-metadata shim is required when using class decorators

Yes, what you’re looking for is possible and works nicely. It appears as though you have the dependencies right. I think you are missing only the following, which needs to be at the beginning of your top level typescript or JavaScript file. Specifically, these need to be prior to the first line is that loads … Read more

tech