- EmberJS Tutorial
- 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 Useful Resources
- EmberJS - Quick Guide
- EmberJS - Useful Resources
- EmberJS - Discussion
EmberJS- Customizing a View's Element
Customizing a View's Element
You can also customize the view's elements by setting up the tagName, classNames and classNameBindings properties in an Ember.View.
Ember.View.extend({ className:'NameofClass' classNameBindings:'AttributeName' tagName:'NameofTag' attributeBindings:'AttributeName' attrvalue:'AttributeValue' });
Example
<!DOCTYPE html> <html> <head> <title>Emberjs Customizing a View's Element</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"> {{view "custom"}} </script> <script type="text/x-handlebars" data-template-name="custom"> <h1>Customizing the view</h1> <!-- using font tag by customizing its attribute in a sView --> <font>I am a Custom View my color is blue</font> </script> <script type="text/javascript"> App = Ember.Application.create(); // Customizing a view's elements: App.CustomView = Ember.View.extend({ //defining name of the template as 'custom' templateName: 'custom', tagName: 'font', //binding the 'color' attribute to the 'font' tag attributeBindings:['color'], //defining value for 'color' attribute 'color': "blue" }); </script> </body> </html>
Output
Let's carry out the following steps to see how above code works −
Save above code in custm_view_elem.htm file
Open this HTML file in a browser.
Advertisements
To Continue Learning Please Login
Login with Google