Skip to content

Commit

Permalink
Merge pull request NativeScript#811 from NativeScript/tsonevn_code_sn…
Browse files Browse the repository at this point in the history
…ippets_edit

changing Page loadedEvent to navigatingTo, on those code snippets whe…
  • Loading branch information
PetyaSotirova authored Jun 22, 2017
2 parents b18683c + e8a0613 commit 62c3b60
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions core-concepts/data-binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ Another common case in working with bindings is requesting access to the parent

### Example 4: Creating ListView child items based on the itemTemplate.
``` XML
<Page loaded="pageLoaded">
<Page navigatingTo="navigatingTo">
<GridLayout rows="*" >{%raw%}
<ListView items="{{ items }}">
<!--Describing how the element will look like-->
Expand All @@ -240,21 +240,21 @@ var pageModule = require("ui/page");

var viewModel = new observable.Observable();

function pageLoaded(args) {
function navigatingTo(args) {
var page = args.object;
viewModel.set("items", [1, 2, 3]);
viewModel.set("test", "Test for parent binding!");
page.bindingContext = viewModel;
}
exports.pageLoaded = pageLoaded;
exports.navigatingTo = navigatingTo;
```
``` TypeScript
import observable = require("data/observable");
import pageModule = require("ui/page");

var viewModel = new observable.Observable();

export function pageLoaded(args: observable.EventData) {
export function navigatingTo(args: observable.EventData) {
var page = <pageModule.Page>args.object;
viewModel.set("items", [1, 2, 3]);
viewModel.set("test", "Test for parent binding!");
Expand Down
24 changes: 12 additions & 12 deletions ui/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ To set a binding for a property in the `XML`, you can use double curly brackets
This sample `main-page.xml` contains a simple label whose text will be populated when the page loads.

```XML
<Page loaded="pageLoaded">
<Page navigatingTo="navigatingTo">
{%raw%}
<Label text="{{ name }}" />
{%endraw%}
Expand All @@ -577,18 +577,18 @@ This sample `main-page.xml` contains a simple label whose text will be populated
This sample `main-page.js` or `main-page.ts` file sets a `bindingContext` for the page. The `bindingContext` contains the custom property and its value. When NativeScript parses `main-page.xml`, it will populate the custom name property with the value in the `bindingContext`.

```JavaScript
function pageLoaded(args) {
function navigatingTo(args) {
var page = args.object;

page.bindingContext = { name: "Some name" };
}
exports.pageLoaded = pageLoaded;
exports.navigatingTo = navigatingTo;
```
```TypeScript
import observable = require("data/observable");
import pages = require("ui/page");

export function pageLoaded(args: observable.EventData) {
export function navigatingTo(args: observable.EventData) {
var page = <pages.Page>args.object;
page.bindingContext = { name: "Some name" };
}
Expand All @@ -600,7 +600,7 @@ export function pageLoaded(args: observable.EventData) {
This sample `main-page.xml` contains a button. The text for the button and the event that the button triggers are determined when the page loads from the matching `main-page.js` or `main-page.ts` file.

```XML
<Page loaded="pageLoaded">
<Page navigatingTo="navigatingTo">
{%raw%}
<Button text="{{ myProperty }}" tap="{{ myFunction }}" />
{%endraw%}
Expand All @@ -610,7 +610,7 @@ This sample `main-page.xml` contains a button. The text for the button and the e
This sample `main-page.js` or `main-page.ts` sets a `bindingContext` for the page. The `bindingContext` contains the custom property for the button text and its value and the custom function that will be triggered when the button is tapped. When NativeScript parses `main-page.xml`, it will populate the button text with the value in the `bindingContext` and will bind the custom function to the tap event.

```JavaScript
function pageLoaded(args) {
function navigatingTo(args) {
var page = args.object;
page.bindingContext = {
myProperty: "Some text",
Expand All @@ -619,13 +619,13 @@ function pageLoaded(args) {
}
};
}
exports.pageLoaded = pageLoaded;
exports.navigatingTo = navigatingTo;
```
```TypeScript
import observable = require("data/observable");
import pages = require("ui/page");

export function pageLoaded(args: observable.EventData) {
export function navigatingTo(args: observable.EventData) {
var page = <pages.Page>args.object;
page.bindingContext = {
myProperty: "Some text",
Expand All @@ -647,7 +647,7 @@ NativeScript can create the items from a template when the `listView` loads insi
In this sample `main-page.xml`, the ListView consists of labels and each item will be created from a template. The text of each label is the value of the name property of the corresponding item.

```XML
<Page loaded="pageLoaded">
<Page navigatingTo="navigatingTo">
{%raw%}
<ListView id="listView1" items="{{ myItems }}">
<ListView.itemTemplate>
Expand All @@ -662,7 +662,7 @@ The sample `main-page.js` or `main-page.ts` populates the `bindingContext` for t

```JavaScript
var view = require("ui/core/view");
function pageLoaded(args) {
function navigatingTo(args) {
var page = args.object;
page.bindingContext = { myItems: [{ name: "Name1" }, { name: "Name2" }, { name: "Name3" }] };

Expand All @@ -672,7 +672,7 @@ function pageLoaded(args) {
// Will not work!
var label1 = view.getViewById(page, "label1");
}
exports.pageLoaded = pageLoaded;
exports.navigatingTo = navigatingTo;
```
```TypeScript
import observable = require("data/observable");
Expand All @@ -681,7 +681,7 @@ import view = require("ui/core/view");
import listView = require("ui/list-view");
import label = require("ui/label");

export function pageLoaded(args: observable.EventData) {
export function navigatingTo(args: observable.EventData) {
var page = <pages.Page>args.object;
page.bindingContext = { myItems: [{ name: "Name1" }, { name: "Name2" }, { name: "Name3" }] };

Expand Down

0 comments on commit 62c3b60

Please sign in to comment.