Reputation: 1834
So the title is pretty self explanatory.
<Switch *ngIf="item.type=='checkbox'" [item]="item" (propertyChange)="onAttributeSwitchChange" row="1" checked="false"></Switch>
public onAttributeSwitchChange(args: observable.PropertyChangeData) {
console.dir(args);
//console.log(args.propertyName + " has been changed and the new value is: " + args.value);
if (args.propertyName === "checked") {
} else {
}
}
I need to get the item
into the onAttributeSwitchChange
And also, i need to make onAttributeSwitchChange
working, because its not now(When i change value the console.dir
doesn't fire).
Reference: https://github.com/NativeScript/NativeScript/issues/1353
Upvotes: 0
Views: 120
Reputation: 1834
Thanks @alexis-cramatte for the tip :)
But here's what worked:
In (Nativescript) NG2 you can access the properties by the ID.
<Switch #switch *ngIf="item.type=='checkbox'" row="1" checked="false" (checkedChange)="onAttributeSwitchChange(switch.checked)"></Switch>
and then you can use the properties of the object by - switch.[propertyhere] - for example: switch.checked
Upvotes: 0
Reputation: 408
I haven't tried but according to nativescript-sdk-examples-ng it should probably look something like this:
my-switch.html
<Switch *ngIf="item.type=='checkbox'" [item]="item" (checkedChange)="onAttributeSwitchChange(item)" row="1" [checked]="switchValue"></Switch>
mySwitchComponent.ts
import {Component} from '@angular/core';
@Component({
selector: "switch-stuff",
templateUrl: "some/path/my-switch.html",
})
export class MySwitchComponent {
switchValue: boolean = false;
constructor() {}
onAttributeSwitchChange(item) {
//do something with item here
}
}
Upvotes: 3