EmberJS-Template Binding Static Class



Description

You can also include the static class in the list of bound properties by prefixing a colon. It makes an element to have a combination of static and bound classes. Do not combine the Bound class names and static class names.

Syntax

<div {{bind-attr class=":literal ClassName"}}>
   <!-- Block -->
</div>

Example

<!DOCTYPE html>
<html>
   <head>
      <title>Emberjs Binding Static Class</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">
         <!-- assigning name for the div class -->
         <div {{bind-attr class=":active App.isEnabled"}}>
            Welcome... check your console for the div tag which displays class name as <b>'is-enabled'</b> and prefixed with literal <b>active</b>.
         </div>
      </script>
      <script type = "text/javascript">
         var App = Ember.Application.create()
         //initializing isEnabled true
         App.isEnabled=true
      </script>
   </body>
</html>

Output

Let's carry out the following steps to see how above code works −

  • Save above code in temp_bind_attr_static_class.htm file

  • Open this HTML file in a browser.

Advertisements