|
1 | 1 | ---
|
2 |
| -title: v-view directive |
3 |
| -contributors: [rigor789, eddyverbruggen] |
| 2 | +title: v-view |
| 3 | +contributors: [rigor789, eddyverbruggen, ikoevska] |
4 | 4 | ---
|
5 | 5 |
|
6 |
| -The `v-view` directive is used to set the current elements `View` as a parent property. |
| 6 | +The `v-view` directive lets you set the current element's `View` as a parent property. |
7 | 7 |
|
8 |
| -### Usage |
| 8 | +--- |
9 | 9 |
|
10 |
| -```html |
| 10 | +```HTML |
11 | 11 | <Child v-view:parentPropertyName />
|
12 | 12 | <!-- same as: -->
|
13 | 13 | <Child ~parentPropertyName />
|
14 | 14 | ```
|
15 | 15 |
|
16 |
| -```html |
| 16 | +```HTML |
17 | 17 | <Child v-view:parentArrayPropertyName.array />
|
18 | 18 | <!-- same as: -->
|
19 | 19 | <Child ~parentArrayPropertyName.array />
|
20 | 20 | ```
|
21 | 21 |
|
22 | 22 | ---
|
23 | 23 |
|
24 |
| -There are many `NativeScript` components that require setting a property to a valid `View` instance, which is not possible using a template. Using this directive saves time by not having to register new directives / references to parent elements, and setting the parent properties manually. |
| 24 | +### Example: `<RadSideDrawer>` |
25 | 25 |
|
26 |
| -To better illustrate what this directive does, let's take a look at the `RadSideDrawer` component from the [Progress NativeScript UI](http://docs.telerik.com/devtools/nativescript-ui/Controls/Angular/SideDrawer/getting-started) package: |
| 26 | +The `<RadSideDrawer>` component is part of the [Progress NativeScript UI](http://docs.telerik.com/devtools/nativescript-ui/Controls/Angular/SideDrawer/getting-started) package. |
27 | 27 |
|
28 |
| -The `RadSideDrawer` component expects the `drawerContent` and `mainContent` properties to be set to `View` instances, |
29 |
| -using the `v-view` directive it would look like this: |
| 28 | +The `<RadSideDrawer>` component requires the `drawerContent` and `mainContent` properties to be set to `View` instances. Using the `v-view` directive, you can do this with a few lines of code: |
30 | 29 |
|
31 |
| -```html |
| 30 | +```HTML |
32 | 31 | <RadSideDrawer>
|
33 | 32 | <StackLayout ~drawerContent />
|
34 | 33 | <StackLayout ~mainContent />
|
35 | 34 | </RadSideDrawer>
|
36 | 35 | ```
|
37 | 36 |
|
38 |
| -Without this directive you would have to do something like: |
| 37 | +Without the `v-view` directive, you need to go a more tedious and error-prone route: |
39 | 38 |
|
40 |
| -```html |
| 39 | +```HTML |
41 | 40 | <RadSideDrawer ref="drawer">
|
42 | 41 | <StackLayout ref="drawerContent" />
|
43 | 42 | <StackLayout ref="mainContent" />
|
44 | 43 | </RadSideDrawer>
|
45 | 44 | ```
|
46 | 45 |
|
47 |
| -```javascript |
| 46 | +```JavaScript |
48 | 47 | {
|
49 | 48 | mounted() {
|
50 | 49 | this.$refs.drawer.nativeView.drawerContent = this.$refs.drawerContent.nativeView
|
51 | 50 | this.$refs.drawer.nativeView.mainContent = this.$refs.mainContent.nativeView
|
52 | 51 | }
|
53 | 52 | }
|
54 |
| -``` |
55 |
| - |
56 |
| -Which can get tedious and is very error prone. |
| 53 | +``` |
0 commit comments