Skip to content

Instantly share code, notes, and snippets.

@billdami
Last active January 13, 2019 18:24
Show Gist options
  • Save billdami/72ee40a6f995578cb67fcbc54b11b563 to your computer and use it in GitHub Desktop.
Save billdami/72ee40a6f995578cb67fcbc54b11b563 to your computer and use it in GitHub Desktop.
Angle Bracket Components
import Controller from '@ember/controller';
export default Controller.extend({
appName: 'Angle Bracket Components'
});
<div class="container">
<h1>{{appName}}</h1>
<div class="row mb-5">
<div class="col-12">
<h4>Inline Components</h4>
<div>
{{!-- classic syntax --}}
{{!-- doesnt work with single word components --}}
{{!-- {{foo name="Bill"}} --}}
{{!-- angle bracket syntax --}}
<Foo @name="Bill" tabindex=5 />
</div>
</div>
</div>
<div class="row mb-5">
<div class="col-12">
<h4>Block Components</h4>
<div>
{{!-- classic syntax --}}
{{#block-component as |cmp|}}
Yielded content
{{cmp.child text="Some value"}}
{{/block-component}}
{{!-- angle bracket syntax --}}
<BlockComponent as |Cmp|>
Yielded content
<Cmp.child @text="Some value" />
</BlockComponent>
</div>
</div>
</div>
</div>
{{outlet}}
import Component from '@ember/component';
export default Component.extend({
classNames: ['block-component']
});
{{yield (hash
child=(component "child-component")
)}}
import Component from '@ember/component';
export default Component.extend({
classNames: ['child-component']
});
Child Component<br>
<strong>Passed arg:</strong> {{text}}
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['foo']
});
Hello, {{name}}!
.foo {
padding: 1rem;
margin-bottom: 0.5rem;
background: lightblue;
border: 1px solid blue;
}
.block-component {
padding: 1rem;
margin-bottom: 0.5rem;
background: lightgreen;
border: 1px solid green;
}
.child-component {
padding: 1rem;
margin-bottom: 0.5rem;
background: limegreen;
border: 1px solid darkgreen;
}
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": true,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3",
"bootstrap": "https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment