Using nativescript 2/angular 2, having problems with data binding. I'm familiar with angularJS 1.x, but the docs I've read on this, this should be working. Tried different variations of ngModel, but not working. The value of record.name is "undefined".
The record class simply has an id and name field defined. My other question is how do you trigger a change event to the component? If a user is starting to type in a text input, how can I call a function in the component as they are typing?
Below is my "html":
<StackLayout>
<Textfield hint="Search for a Record" [(ngModel)]="record.name" (returnPress)="searchRecord()"></Textfield>
<Label text="{{ record.name }}"></Label>
<Button text="Search" class="btn" (tap)="searchRecord()"></Button>
<Button text="Take Photo" class="btn" (tap)="takePhoto()"></Button>
</StackLayout>
Add record component:
import {Component} from "@angular/core";
import cameraModule = require("camera");
import imageModule = require("ui/image");
import {Record} from "../../shared/record/record";
import {RecordService} from "../../shared/record/record-service";
@Component({
selector: "add-record",
templateUrl: "pages/add-record/add-record.html",
styleUrls: ["pages/add-record/add-record-common.css"],
providers: [ RecordService ]
})
export class AddRecordPage {
record: Record;
constructor(private _recordService: RecordService) {
this.record = new Record();
}
searchRecord() {
console.log(this.record.name + '!');
this._recordService.add(this.record)
.subscribe(
() => {
alert('a');
},
() => {
alert('b');
}
);
}
takePhoto() {
cameraModule.takePicture().then(picture => {
console.log("Result is an image source instance");
var image = new imageModule.Image();
image.imageSource = picture;
});
}
}
Thanks!