⚠️ This lesson is retired and might contain outdated information.

Bind data to NativeScript Angular components using RxJS Observables

Nathan Walker
InstructorNathan Walker
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 2 months ago

Learn how to use standard RxJS Observables for your native view bindings using the power of Angular’s async pipe.

[00:00] Because we have the power of Angular at our fingertips, we can also bind two observables. Let's import from RxJS. We'll use the behavior subject. Let's convert our items to be a behavior subject.

[00:12] Let's actually use the items to set this up. We're going to reference these here, and we're going to convert this to a behavior subject to be typed as an array of any type of object. We'll instantiate it, and we'll initialize it to an empty array.

[00:26] Then to demonstrate, we'll set up a counter that will just fire off an interval every second. We'll take our behavior subject and we're going to emit out a new array each time using an immutable data structure pattern.

[00:40] We're going to grab the latest value of what's in our observable, and then we're going to append the latest item that's in our account. Then we'll just increment the counter. For good measure, only if count is less than four, otherwise we'll just kill the tie run.

[00:56] Now, let's bind to our items observable using Angular's Asynch pipe. We can see our list view now is just reacting to the changes on that observable automatically.

egghead
egghead
~ 11 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today