两种方式绑定不起作用。我刚开始学习,也许我错过了一些非常基本的东西,感谢您的关注和回复。
详情如下:
package.json
{
"name": "agaminsstart",
"main": "app.js",
"version": "1.0.0",
"author": "babul.prasad@xyz.com",
"description": "Nativescript Angular Base Application",
"license": "SEE LICENSE IN <your-license-filename>",
"readme": "NativeScript Application",
"repository": "<fill-your-repository-here>",
"nativescript": {
"id": "org.nativescript.MyApp",
"tns-ios": {
"version": "2.2.1"
},
"tns-android": {
"version": "2.2.0"
}
},
"dependencies": {
"@angular/common": "2.0.0-rc.6",
"@angular/compiler": "2.0.0-rc.6",
"@angular/core": "2.0.0-rc.6",
"@angular/http": "2.0.0-rc.6",
"@angular/platform-browser": "2.0.0-rc.6",
"@angular/platform-browser-dynamic": "2.0.0-rc.6",
"@angular/platform-server": "2.0.0-rc.6",
"@angular/router": "3.0.0-rc.2",
"nativescript-angular": "0.5.0",
"reflect-metadata": "^0.1.8",
"rxjs": "5.0.0-beta.11",
"tns-core-modules": "^2.2.1",
"zone.js": "0.6.17"
},
"devDependencies": {
"babel-traverse": "6.15.0",
"babel-types": "6.15.0",
"babylon": "6.9.2",
"lazy": "1.0.11",
"nativescript-dev-typescript": "^0.3.2",
"typescript": "^1.8.10"
}
}
应用程序.ts
import { platformNativeScriptDynamic } from "nativescript-angular/platform";
import { AppModule } from "./app.module";
platformNativeScriptDynamic().bootstrapModule(AppModule);
app.module.ts
import { NativeScriptModule } from "nativescript-angular/platform";
import { NgModule } from "@angular/core";
import { AppComponent } from "./components/login/app.component"
@NgModule({
declarations: [AppComponent],
bootstrap: [AppComponent],
imports: [NativeScriptModule],
exports: []
})
export class AppModule { }
app.component.ts
import {Component} from "@angular/core";
import {User} from "./user";
@Component({
selector: "my-app",
templateUrl: "./components/login/app.component.html",
styleUrls: [ "components/login/login.css"]
})
export class AppComponent {
public user : User;
constructor(){
//this.email = "babul.prasad@xyz.com";
this.user = new User();
this.user.email = "ngconf@telerik33.com";
this.user.password = "password";
}
submit() {
alert("You are using "+this.user.email+" : "+this.user.password);
}
}
用户.ts
export class User {
email: string;
password: string;
}
app.component.html
<StackLayout>
<Image src="~/images/pig1.png" stretch="none" horizontalAlignment="center"></Image>
<TextField #email hint="Email Address" keyboardType="email" [(ngModel)]="user.email" text="{{user.email}}" autocorrect="false" autocapitalizationType="none"></TextField>
<TextField #password hint="Password" secure="true" [(ngModel)]="user.password" text="{{user.password}}"></TextField>
<Button text="Sign in" class="submit-button" (tap)="submit()"></Button>
<Button text="Sign up" class="submit-button"></Button>
</StackLayout>