Last active
June 6, 2019 06:32
-
-
Save djedi/060f4d1db4bf7679af00296c0fdd8e5b to your computer and use it in GitHub Desktop.
Basic Dependency Injection Example
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
<template> | |
<require from="./comp1"></require> | |
<require from="./comp2"></require> | |
<comp1></comp1> | |
<comp2></comp2> | |
</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
export class App { | |
} |
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
<template> | |
<require from="./comp1child"></require> | |
<div> | |
Comp1: ${shared.val}<br> | |
<button click.delegate="setVal()">Set Value</button> | |
</div><br> | |
<comp1child></comp1child> | |
</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
import {inject} from 'aurelia-framework'; | |
import {Shared} from 'shared-service'; | |
@inject(Shared) | |
export class Comp1 { | |
constructor(shared) { | |
this.shared = shared; | |
} | |
setVal() { | |
this.shared.val = 'Component 1 set value'; | |
} | |
} |
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
<template> | |
<div> | |
Child component, edit value: | |
<input type="text" value.bind="shared.val"> | |
</div><br> | |
</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
import {inject} from 'aurelia-framework'; | |
import {Shared} from 'shared-service'; | |
@inject(Shared) | |
export class Comp1child { | |
constructor(shared) { | |
this.shared = shared; | |
} | |
} |
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
<template> | |
<require from="./comp2child.html"></require> | |
<div> | |
Comp2: ${shared.val} | |
</div> | |
<button click.delegate="setVal()">Set Value</button><br><br> | |
<comp2child val.two-way="shared.val"></comp2child> | |
</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
import {inject} from 'aurelia-framework'; | |
import {Shared} from 'shared-service'; | |
@inject(Shared) | |
export class Comp2 { | |
constructor(shared) { | |
this.shared = shared; | |
} | |
setVal() { | |
this.shared.val = 'Component 2 set value'; | |
} | |
} |
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
<template bindable="val"> | |
<div> | |
Comp2 Child component with no view-model.<br> | |
Edit here too: <input type="text" value.bind="val"> | |
</div> | |
</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
<!doctype html> | |
<html> | |
<head> | |
<title>Aurelia</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body aurelia-app> | |
<h1>Loading...</h1> | |
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script> | |
<script> | |
require(['aurelia-bootstrapper']); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment