-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add aurelia 2 * remove template from au2
- Loading branch information
1 parent
2a52125
commit fbf1f0b
Showing
57 changed files
with
433 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Hello ${name}</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class Name { | ||
name = "John"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Hello ${name}</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class Name { | ||
name = "John"; | ||
|
||
constructor() { | ||
this.name = "Jane"; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
content/1-reactivity/3-computed-state/aurelia2/double-count.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div>${doubleCount}</div> |
4 changes: 4 additions & 0 deletions
4
content/1-reactivity/3-computed-state/aurelia2/double-count.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export class DoubleCount { | ||
count: number = 10; | ||
doubleCount = this.count * 2; | ||
} |
1 change: 1 addition & 0 deletions
1
content/2-templating/1-minimal-template/aurelia2/hello-world.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Hello world</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.title { | ||
color: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1 class="title">I am red</h1> | ||
<button style="font-size: 10rem">I am a button</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<ul> | ||
<li repeat.for="color of colors">${color}</li> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class Colors { | ||
colors = ["red", "green", "blue"]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<p>Counter: ${count}</p> | ||
<button click.trigger="incrementCount">+1</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class Counter { | ||
count: number = 0; | ||
|
||
incrementCount() { | ||
this.count++; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<input ref="inputElement" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class InputFocused { | ||
inputElement: HTMLInputElement; | ||
|
||
attached() { | ||
this.inputElement.focus(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
content/2-templating/6-conditional/aurelia2/traffic-light.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<button click.trigger="nextLight()">Next light</button> | ||
<p>Light is: ${light}</p> | ||
<p switch.bind="light"> | ||
You must | ||
<span case="red">STOP</span> | ||
<span case="orange">SLOW DOWN</span> | ||
<span case="green">GO</span> | ||
</p> |
16 changes: 16 additions & 0 deletions
16
content/2-templating/6-conditional/aurelia2/traffic-light.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const TRAFFIC_LIGHTS = ["red", "orange", "green"]; | ||
|
||
export class App { | ||
lightIndex = 0; | ||
get light() { | ||
return TRAFFIC_LIGHTS[this.lightIndex]; | ||
} | ||
|
||
nextLight() { | ||
if (this.lightIndex + 1 > TRAFFIC_LIGHTS.length - 1) { | ||
this.lightIndex = 0; | ||
} else { | ||
this.lightIndex++; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>Page title is: ${pageTitle}</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class PageTitle { | ||
pageTitle = ""; | ||
|
||
attached(): void { | ||
this.pageTitle = document.title; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>Current time: ${time}</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export class Time { | ||
time: string = new Date().toLocaleTimeString(); | ||
timer: number; | ||
|
||
constructor() { | ||
this.timer = setInterval(() => { | ||
this.time = new Date().toLocaleTimeString(); | ||
}, 1000); | ||
} | ||
|
||
dispose() { | ||
clearInterval(this.timer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<user-profile | ||
name.bind | ||
age.bind | ||
favourite-colors.bind="colors" | ||
is-available.bind="available" | ||
></user-profile> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { UserProfile } from "./user-profile"; | ||
|
||
export class App { | ||
static dependencies = [UserProfile]; // static dependecies way or registered globablly | ||
age = 20; | ||
name = "John"; | ||
colors = ["green", "blue", "red"]; | ||
available = false; | ||
} |
4 changes: 4 additions & 0 deletions
4
content/4-component-composition/1-props/aurelia2/user-profile.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<p>My name is ${name}</p> | ||
<p>My age is ${age}</p> | ||
<p>My favourite colors are ${favouriteColors.join(", ")}</p> | ||
<p>I am ${isAvailable ? "available" : "not available"}</p> |
8 changes: 8 additions & 0 deletions
8
content/4-component-composition/1-props/aurelia2/user-profile.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { bindable } from "aurelia"; | ||
|
||
export class UserProfile { | ||
@bindable name = ""; | ||
@bindable age = null; | ||
@bindable favouriteColors = []; | ||
@bindable isAvailable = true; | ||
} |
2 changes: 2 additions & 0 deletions
2
content/4-component-composition/2-emit-to-parent/aurelia2/answer-button.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<button click.trigger="actionHandler(true)">YES</button> | ||
<button click.trigger="actionHandler()">NO</button> |
5 changes: 5 additions & 0 deletions
5
content/4-component-composition/2-emit-to-parent/aurelia2/answer-button.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { bindable } from "aurelia"; | ||
|
||
export class AnswerButton { | ||
@bindable actionHandler; | ||
} |
3 changes: 3 additions & 0 deletions
3
content/4-component-composition/2-emit-to-parent/aurelia2/app.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<p>Can I come ?</p> | ||
<answer-button action-handler.bind="handleAnswer"></answer-button> | ||
<p style="font-size: 50px">${canCome ? "馃榾" : "馃槬"}</p> |
7 changes: 7 additions & 0 deletions
7
content/4-component-composition/2-emit-to-parent/aurelia2/app.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class App { | ||
canCome = false; | ||
|
||
handleAnswer = (answer = false) => { | ||
this.canCome = answer; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<funny-button>Click me !</funny-button> |
19 changes: 19 additions & 0 deletions
19
content/4-component-composition/3-slot/aurelia2/funny-button.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<let | ||
style=" | ||
color: #fff; | ||
padding: 10px 20px; | ||
font-size: 30px; | ||
border: 2px solid #fff; | ||
margin: 8px; | ||
transform: scale(0.9); | ||
box-shadow: 4px 4px rgba(0, 0, 0, 0.4); | ||
transition: transform 0.2s cubic-bezier(0.34, 1.65, 0.88, 0.925) 0s; | ||
outline: 0; | ||
background: rgba(0, 0, 0, 0.4); | ||
" | ||
> | ||
</let> | ||
|
||
<button style.bind="style"> | ||
<au-slot></au-slot> | ||
</button> |
2 changes: 2 additions & 0 deletions
2
content/4-component-composition/4-slot-fallback/aurelia2/app.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<funny-button></funny-button> | ||
<funny-button>Click me !</funny-button> |
19 changes: 19 additions & 0 deletions
19
content/4-component-composition/4-slot-fallback/aurelia2/funny-button.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<let | ||
style=" | ||
background: rgba(0, 0, 0, 0.4); | ||
color: #fff; | ||
padding: 10px 20px; | ||
font-size: 30px; | ||
border: 2px solid #fff; | ||
margin: 8px; | ||
transform: scale(0.9); | ||
box-shadow: 4px 4px rgba(0, 0, 0, 0.4); | ||
transition: transform 0.2s cubic-bezier(0.34, 1.65, 0.88, 0.925) 0s; | ||
outline: 0; | ||
" | ||
> | ||
</let> | ||
|
||
<button style.bind="style"> | ||
<au-slot> No content </au-slot> | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Welcome back, {{ user.username }}</h1> | ||
<user-profile /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { user } from "./user-profile"; | ||
|
||
export class App { | ||
user = user; | ||
} |
8 changes: 8 additions & 0 deletions
8
content/4-component-composition/5-context/aurelia2/user-profile.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div> | ||
<h2>My Profile</h2> | ||
<p>Username: ${ user.username }</p> | ||
<p>Email: ${ user.email }</p> | ||
<button click.trigger="user.username = 'Jane'"> | ||
Update username to Jane | ||
</button> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
content/4-component-composition/5-context/aurelia2/user-profile.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const user = { | ||
id: 1, | ||
username: "unicorn42", | ||
email: "[email protected]", | ||
}; | ||
|
||
export class UserProfile { | ||
user = user; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<p>${text}</p> | ||
<input value.bind /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class InputHello { | ||
value: string = "Hello World"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<input id="is-available" type="checkbox" checked.bind="isAvailable" /> | ||
<label for="is-available">Is available</label>: ${isAvailable} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class IsAvailable { | ||
isAvailable = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div>Picked: ${picked}</div> | ||
|
||
<input id="blue-pill" checked.bind="picked" type="radio" value="blue" /> | ||
<label for="blue-pill">Blue pill</label> | ||
|
||
<input id="red-pill" checked.bind="picked" type="radio" value="red" /> | ||
<label for="red-pill">Red pill</label> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class PickPill { | ||
picked = "red"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<select value.bind="selectedColorId"> | ||
<option value="">Select A Color</option> | ||
<option | ||
repeat.for="color of colors" | ||
value.bind="color.id" | ||
disabled.bind="color.isDisabled" | ||
> | ||
${color.text} | ||
</option> | ||
</select> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const colors = [ | ||
{ id: 1, text: "red" }, | ||
{ id: 2, text: "blue" }, | ||
{ id: 3, text: "green" }, | ||
{ id: 4, text: "gray", isDisabled: true }, | ||
]; | ||
|
||
export class Select { | ||
selectedColorId = 2; | ||
colors = colors; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Hello world</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export class App {} |
10 changes: 10 additions & 0 deletions
10
content/7-webapp-features/1-render-app/aurelia2/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script type="module" src="./main.ts"></script> | ||
</head> | ||
|
||
<body> | ||
<app></app> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Aurelia } from "aurelia"; | ||
import { App } from "./app"; | ||
|
||
Aurelia.app(App).start(); |
19 changes: 19 additions & 0 deletions
19
content/7-webapp-features/2-fetch-data/aurelia2/UseFetchUsers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export class UseFetchUsers { | ||
data = null; | ||
error = null; | ||
isLoading = false; | ||
|
||
async fetchData() { | ||
this.isLoading = true; | ||
try { | ||
const response = await fetch("https://randomuser.me/api/?results=3"); | ||
const { results: users } = await response.json(); | ||
this.data = users; | ||
this.error = null; | ||
} catch (err) { | ||
this.data = null; | ||
this.error = err; | ||
} | ||
this.isLoading = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<template promise.bind="useFetchUsers.fetchData()"> | ||
<p pending>Fetching users...</p> | ||
<p catch>An error ocurred while fetching users</p> | ||
<ul then.from-view="users"> | ||
<li repeat.for="user of users"> | ||
<img src.bind="user.picture.thumbnail" alt="user" /> | ||
<p>${ user.name.first } ${ user.name.last }</p> | ||
</li> | ||
</ul> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { UseFetchUsers } from "./UseFetchUsers"; | ||
|
||
export class App { | ||
// eslint-disable-next-line no-unused-vars | ||
constructor(private useFetchUsers: UseFetchUsers) {} | ||
} |
12 changes: 12 additions & 0 deletions
12
content/7-webapp-features/3-router-link/aurelia2/router-link.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
See [Add routes and a viewport](https://docs.aurelia.io/routing/router-tutorial#add-routes-and-a-viewport) | ||
|
||
```html | ||
<ul> | ||
<li> | ||
<a load="/home">Home</a> | ||
</li> | ||
<li> | ||
<a load="/about">About</a> | ||
</li> | ||
</ul> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export class App { | ||
static routes = [ | ||
{ | ||
path: ["", "home"], | ||
}, | ||
]; | ||
static template = "<au-viewport></au-viewport>"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.