Showing posts with label Angular-Route. Show all posts
Showing posts with label Angular-Route. Show all posts

Monday, August 24, 2015

Using Polymer 1.0 with AngularJs Route

Step 1:
install polymer form its official site polymer-project.org, best way to download polymer is by using
bower : bower install --save Polymer/polymer#^1.0.0

Step 2:
set up your site's main page i.e index.html using the components what you like. You can see the code of my index.html file here

Step 3:
Now add the angular js plugins in the end of header in index page as below
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.3/angular-route.min.js"></script>

Step 4:
Now create angular app by initiating it by using ng-app="shaharma"in the body tag
<body  unresolved class="fullbleed layout vertical" ng-app="shaharma">

Step 5:
We are going to do route by using the hash(#) routing technique. Now update the link tag with # link tag as below:

     <paper-menu class="list" >
          <a href="#/">
            <iron-icon icon="home"></iron-icon>
            <span>Home</span>
          </a>
          <a href="#/about">
            <iron-icon icon="info"></iron-icon>
            <span>Users</span>
          </a>
          <a href="#/contact">
            <iron-icon icon="mail"></iron-icon>
            <span>Contact</span>
          </a>
        </paper-menu>
Now create a file named angular.js where we are going to add the route technique for our website. The final code is here

Step 6:
define a content area where the view are tobe loaded by using  ng-view
<div class="content" ng-view></div>

Step 7:
Now lets create a webelements which are going to be displayed inthe content section during the routing:
inside the elements folder we can see the web components for the different view which can be view here
example : for contact-form view

<dom-module id="contact-form">
  <style is="custom-style">
      paper-card {width: 100%-20px;margin: 10px;}
      #heading{color: #313131;font-size: 16px;font-weight: bold;
      .content.paper-button {padding: 0; }
  </style>
  <template is="dom-bind">
    <h4>Character counter</h4>
    <div class="vertical-section">
      <paper-input label="label" char-counter></paper-input>
      <paper-input label="at most 10 letters" char-counter auto-validate pattern="[a-zA-Z]*" maxlength="10" error-message="letters only!"></paper-input>
      <paper-textarea label="textarea" char-counter></paper-textarea>
      <paper-textarea label="textarea with maxlength" char-counter maxlength="10"></paper-textarea>
      <paper-textarea label="text area with rows and max-rows" rows="3" max-rows="4"><paper-textarea>
    </div>
  </template>

<script>
(function() {
  Polymer({
    is: 'contact-form' 
  });
})();
</script>
</dom-module>

Step 8: register all the elements in the single elements.html page
 elements/elements.html
Full working code can be found here and demo can be viewd here

Tuesday, January 13, 2015

Features of Angular JS

Core Features of Angular JS

The core features of AngularJS are as follows:
Data-binding: It is the automatic synchronization of data between model and view components.
Scope: These are objects that refer to the model. They act as a glue between controller and view.
Controller: These are JavaScript functions bound to a particular scope.
Services: AngularJS comes with several built-in services such as $http to make a XMLHttpRequests. These are singleton objects which are instantiated only once in app.
Filters: These select a subset of items from an array and returns a new array.
Directives: Directives are markers on DOM elements such as elements, attributes, css, and more. These can be used to create custom HTML tags that serve as new, custom widgets. AngularJS has built-in directives such as ngBind, ngModel, etc.
Templates:These are the rendered view with information from the controller and model. These can be a single file (such as index.html) or multiple views in one page using partials.
Routing: It is concept of switching views.
Model View Whatever: MVW is a design pattern for dividing an application into different parts called Model, View, and Controller, each with distinct responsibilities. AngularJS does not implement MVC in the traditional sense, but rather something closer to MVVM (Model-View-ViewModel). The Angular JS team refers it humorously as Model View Whatever.
Deep Linking: Deep linking allows to encode the state of application in the URL so that it can be bookmarked. The application can then be restored from the URL to the same state.
Dependency Injection: AngularJS has a built-in dependency injection subsystem that helps the developer to create, understand, and test the applications easily.

What is Anguar JS - First Step

AngularJS is quite new. Version 1.0 was released in 2012. Miško Hevery, a Google employee, started to work on AngularJS in 2009. The idea turned out very good, and the project is now officially backed by a Google development team.
AngularJS is a JavaScript framework. It is a library written in JavaScript.
AngularJS is distributed as a JavaScript file, and can be added to a web page with a script tag:

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>