Created by Aysegul Yonet /
twitter@AysSomething
Slides: bit.ly/ForwardJS-Angular2
Verify that you are running at least node v6.x.x and npm 3.x.x by running node -v and npm -v in a terminal/console window.
npm -g list -depth=0
npm uninstall -g angular-cli @angular/cli
npm cache clean
npm install -g @angular/cli@latest
npm i -g typescript
npm install @angular/{common,compiler,compiler-cli,core,forms,http,platform-browser,platform-browser-dynamic,platform-server,router,animations}@next --sav
Loading...
{{ user.name }}
var notSure: any = 4;
notSure = "maybe a string instead";
notSure = false;
// For collections, there are typed arrays and generic arrays
let list: number[] = [1, 2, 3];
// Alternatively, using the generic array type
let list: Array<number> = [1, 2, 3];
let projects: ProjectType[] =
export type SlideElement = Text | Image | Lmv;
var f1 = function(i: number): number { return i * i; }
// Return type inferred
var f2 = function(i: number) { return i * i; }
var f3 = (i: number): number => { return i * i; }
// Return type inferred
var f4 = (i: number) => { return i * i; }
// Return type inferred, one-liner means no return keyword needed
var f5 = (i: number) => i * i;
Hello, {{name}}!
function chartDirective () {
return {
restrict: ‘E’,
scope: {
data:"parentData"
},
link: link
};
};
function link () {}
function chartDirective () {
return {
restrict: ‘E’,
scope: {},
bindToController: {
data:"parentData"
}
link: link
};
};
function link () {}
I am a message
{{ref.value}}
- {{message}}
//lib.js
export function square(x) {
return x * x;
}
// main.js
import { square } from 'lib';
//lib.js
export class Math{
this.square(){}
}
// main.js
import { Math } from 'lib';
//main.ts
import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';
bootstrap(AppComponent, []);
document.addEventListener('DOMContentLoaded', function () {
ng.platform.browser.bootstrap(MyAppComponent, [MyService, ng.core.provide(...)]);
});
@Component({
selector: 'post-list'
})
(function(app) {
app.AppComponent =
ng.core.Component({
selector: 'my-app',
template: 'My First Angular 2 App
'
})
.Class({
constructor: function() {}
});
})(window.app || (window.app = {}));
@Component({
selector: 'catstagram',
})
export Class Catstagram {
constructor(){
this.posts = [];
}
}
@Component({
selector: 'catstagram',
templateUrl:'posts.html'
})
export Class Catstagram {
constructor(){
this.posts = [];
}
}
@Component({
selector: 'catstagram',
templateUrl:'posts.html',
})
export Class Catstagram {
constructor(){
this.posts = [];
}
}
angular
.module('app')
.directive('catstagram', catstagramComponent);
function catstagramComponent () {
var directive = {
scope: {
data:'=data'
},
link: createComponent
}
return directive;
function createComponent () {}
}
angular
.module('app')
.directive('catstagram', catstagramComponent);
function catstagramComponent () {
var directive = {
scope: {
data:'=data'
},
controller:catController,
link: createComponent
}
return directive;
function createComponent () {}
function catController (){...}
}
@Component({
selector: 'catstagram',
templateUrl:'posts.html',
})
export Class Catstagram {
@Input() data;
constructor(){
this.posts = this.data;
}
}
ng new ay-slides --style=sass
@Component({
selector:'child',
template:'{{data}}
'
})
export class ChildComponent {
@Input() data;
}
@Component({
selector:'parent',
template:' '
})
export class ParentComponent {
onChildEvent(ev){
console.log('Event fired',ev);
}
}
@Component({
selector:'child',
template:''
})
export class ChildComponent {
@Output childEvent = new EventEmitter();
onClick(){
this.childEvent.emit('hello!');
}
}
import { Injectable } from '@angular/core';
@Injectable()
export class DataService(){
return [...];
}
import { provideRouter, RouterConfig } from '@angular/router';
import { HomeComponent, ListComponent } fromt './..';
import { provideRouter, RouterConfig } from '@angular/router';
const routes: RouterConfig = [
{
path: '',
redirectTo: '/home',
pathMatch: 'full'
},
{
path: 'home',
component: HomeComponent
},
{
path: 'about',
component: AboutComponent
}
];
export const appRouterProviders = [
provideRouter(routes)
];
import { ROUTER_DIRECTIVES } from '@angular/router';
- Slides
- @AysegulYonet