Code Monkey home page Code Monkey logo

angular2-study's Introduction

####Controlling Rendering HTML

  • ngIf
  • ngSwitch
  • ngFor
  • Pipes
  • Creating Custom Pipes
  • ngClass

Showing / hiding elements

<div [hidden]="courses.length == 0"></div>	
<div *ngIf="courses.length	> 0"></div>	
<div [ngSwitch]="viewMode">
    <template [ngSwitchWhen]="'map'" ngSwitchDefault>
        ...
    </template>
    <template [ngSwitchWhen]="'list'">
        ...
    </template>
</div>	

Pipes

{{	course.title	|	uppercase	}}	->	ANGULAR	COURSE
{{	course.students	|	number	}}	->	1,234
{{	course.rating	|	number:’2.2-2	}}	->	04.97
{{	course.price	|	currency:’USD’:true	}}	->	$99.95
{{	course.releaseDate	|	date:’MMM	yyyy’	}}	->	Mar	2016
{{	course	|	json	}}

Creating Custom Pipes

import {Pipe, PipeTransform} from ‘angular2/core’;	
@Pipe({	name: ‘summary’	})
export	class	SummaryPipe	implements	PipeTransform	{
    transform(value:	string,	args:	string[])	{
    }
}

In the host component

@Component({
    pipes: [SummaryPipe]
})

Applying multiple classes dynamically

<i [ngClass]={
    active: isActive,
    disabled: isDisabled
}></i>	

Applying multiple styles dynamically

<button	
    [ngStyle]={
    backgroundColor:	canSave	?	‘blue’:	‘gray’,
    color:	canSave	?	‘white’	:	‘black’
}></button>

Elvis operator

{{	task.assignee?.role?.name	}}

Inserting content from the outside

<ng-content></ng-content>	
Multiple content placeholders
<ng-content	select=.heading”></ng-content>
<ng-content	select=.body”></ng-content>

angular2-study's People

Watchers

James Cloos avatar sumin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.