1

I'm attempting to bind an Observable to a RadListView, without using any Page properties, but appear to be doing something completely wrong. The following is a minified version of the code.

The component:

export class WeatherComponent implements OnInit {
    public weather : ObservableArray<StringWrapper>;

    constructor(private _weatherService : WeatherService) {
        this.weather = new ObservableArray<StringWrapper>([]);
        this.weather.push(<StringWrapper>{value:'Sunny'});
    }

    ngOnInit(): void {
        this._weatherService.getDummyWeather().subscribe(
            item => {
                this.weather.push(item);
            }
        );
    }
}

The XML:

<RadListView [items]="weather">
    <template tkListItemTemplate let-item="item">
        <StackLayout orientation="vertical">
            <Label [text]="item.value"></Label>
        </StackLayout>
    </template>
</RadListView>

The simple data model:

export interface StringWrapper {
    value : string;
}

The service:

@Injectable()
export class WeatherService {
    public getDummyWeather() : Observable<StringWrapper> {
        return Observable.of(<StringWrapper>{value:'Rainy'});
    }
}

The service is correctly updating the model but the view is not reflecting the changes, leading me to believe the problem is located in the observable binding.

Any help would be deeply appreciated!

N.B. Checked related questions and none of the solutions helped, i.e. Nativescript RadListView not binding to source property solution causes a build error.

Community
  • 1
  • 1
SeanTheStudent
  • 75
  • 1
  • 1
  • 7
  • This binding `text="{{value}}"` is only for XML meaning NativeScript without Angular. When working with {N} + Angular you need to use Angular's biding syntax which is `[text]="value"` – Vladimir Amiorkov Mar 05 '17 at 18:32
  • @VladimirAmiorkov Thanks for the reply and help! I've modified the code to take into account the Angular bindings (I assumed Angular2's interpolation was somehow being used before) but to no avail; the UI still doesn't reflect the changes. I've compared your sample code on Github but can't really see any differences. – SeanTheStudent Mar 05 '17 at 20:23

1 Answers1

0

Change the HTML to

 <RadListView  [items]="weather" >
        <template tkListItemTemplate let-item="item">
            <StackLayout class="itemStackLayout" >
                <Label class="titleLabel" [text]="item.value" textWrap="true" width="100%"></Label>
            </StackLayout>
        </template>
 </RadListView>

Hint: Seems like stringwrapper is not need. You can use below code if it just a string array

 <Label class="titleLabel" [text]="item" textWrap="true" width="100%"></Label>
Habeeb
  • 1,020
  • 16
  • 35
  • Hi, thanks for the reply. Unfortunately, this didn't appear to make any difference, since the UI still fails to update. Regarding the StringWrapper class, it's just for demo purposes. – SeanTheStudent Mar 05 '17 at 19:46