- EmberJS - Home
- EmberJS - Overview
- EmberJS - Installation
- EmberJS - Core Concepts
- Creating and Running Application
- EmberJS - Object Model
- EmberJS - Router
- EmberJS - Templates
- EmberJS - Components
- EmberJS - Models
- EmberJS - Managing Dependencies
- EmberJS - Application Concerns
- EmberJS - Configuring Ember.js
- EmberJS - Ember Inspector
EmberJS-Components Customizing Attributes
Description
You can customize the attributes using attributeBindings property that bind attributes to the DOM element.
Syntax
Ember.Component.extend({
tagName: 'Valid HTML5 tag',
attributeBindings: ['AttributeName'],
AttributeName: "ValueForAttribute"
});
Example
<!DOCTYPE html>
<html>
<head>
<title>Emberjs Customizing Attributes</title>
<!-- CDN's -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.1/handlebars.min.js"></script>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.10.0/ember.min.js"></script>
<script src="https://builds.emberjs.com/tags/v1.10.0-beta.3/ember-template-compiler.js"></script>
<script src="https://builds.emberjs.com/release/ember.debug.js"></script>
<script src="https://builds.emberjs.com/beta/ember-data.js"></script>
</head>
<body>
<script type="text/x-handlebars" data-template-name="application">
<h3>Customizing HTML 'font' tag Attribute</h3>
<!-- specfying the component name with title var -->
{{my-tag title=title}}
</script>
<script type="text/x-handlebars" data-template-name="components/my-tag">
<!-- displaying the title value -->
{{title}}
</script>
<script type="text/javascript">
App = Ember.Application.create();
App.ApplicationRoute = Ember.Route.extend({
model: function() {
return {
title: 'Welcome to Tutorialspoint...'
};
}
});
App.MyTagComponent =Ember.Component.extend({
//specifying the tag name property as 'font'
tagName: 'font',
//binding the 'color' attribute in the 'font' tag
attributeBindings: ['color'],
//specifying the value for 'color' attribute as 'red'
color: "red"
});
</script>
</body>
</html>
Output
Let's carry out the following steps to see how above code works −
Save above code in comp_custm_attr.htm file
Open this HTML file in a browser.
Advertisements