NativeScript - Switch

Switch 就是 switch…切换的

基本就是拿checked属性来给别的组建做判断
改改颜色还是不错的
目前change的用tap来捕获

import {Component, ViewChild, ElementRef} from "angular2/core";
import {Color} from "color";
import {SearchBar} from "ui/search-bar";
import {TextField} from "ui/text-field";
import {Switch} from "ui/switch";

@Component({
selector: "my-app",
template: `
<StackLayout orientation="vertical">
<TextField></TextField>
<SearchBar *ngIf="sw.checked" #searchBar hint="searchHint" [(ngModel)]='search'></SearchBar>
<Switch #sw style="color:red" (tap)="change()" [(ngModel)]="checked" ></Switch>
</StackLayout>
`,
styleUrls: ["app.css"]
})
export class AppComponent {

_search: string = "searchText";
nsSearchBar: SearchBar;
private _checked: boolean = false;

public set checked(v: boolean) {
this._checked = v;
console.log("set", this._checked);
}


public get checked(): boolean {
console.log("get", this._checked);
return this._checked;
}


public get search(): string {
return this._search
}


public set search(v: string) {
console.log("set search");
this._search = v;
}


@ViewChild('searchBar') ngSearchBar: ElementRef;

constructor() {
}

ngAfterViewInit() {


}
change() {
console.log("change");
}
}