AngularJS – Directives(2)

by show a simple ‘tabbing’ example’, this page explains about ‘ng-click’, ‘ng-init’, and ‘ng-class’ directives.

 

First Phase

<section>
<ul class=”nav nav-pills”>
<li> <a href ng-click=”tab = 1″> Tab 1 </a> </li>
<li> <a href ng-click=”tab = 2″> Tab 2 </a> </li>
<li> <a href ng-click=”tab = 3″> Tab 3 </a> </li>
</ul>
<div class=”panel” ng-show=”tab === 1″>
</div>
<div class=”panel” ng-show=”tab === 2″>
</div>
<div class=”panel” ng-show=”tab === 3″>
</div>
</section>

  • ng-click directive launches a work
  • in the example, it puts 1, 2, and 3 values into the ‘tab’ variable.
  • furthermore, only a <div> area will be displayed by ‘tab’ variable.

 

Second Phase

<section ng-init=”tab = 1″>
…….
</section>

  • ng-init directive can initialize the value of a variable.
  • however, initializing the value of a variable would be better in a related controller.

 

Third Phase

<section ng-init=”tab = 1″>
…….
<li ng-class=”{ class_name:tab === 1}”>
<a href ng-click=”tab = 1″> Tab 1 </a>
</li>
…….
</section>

  • ng-class directive takes an array of key and value.
  • if the value (tab === 1) is true, the key (class_name) will be added as a class to the tag (<li>)
  • if the value is false, class_name won’t be added.

AngularJS – Filters(1)

By adding filters, you could get a write form to express a data.

In AngularJS, we use ‘|’, a pipeline for combining a data with filter.

 

currency

  • ${{data.price | currency}}
  • currency filter automatically do the job for localisation.
  • output (assuming we are in the U.S)
    $10.00

 

date

  • {{date_expression | date}}
  • example
    {{‘1388123412323′ | date:’MM/dd/yyyy @ h:mma’}}
  • output
    12/27/2013 @ 12:50AM

uppercase

  • {{‘octagon gem’ | uppercase}
    => OCTAGON GEM

 

limitTo

  • {{‘My Description’ | limitTo:8}}
    => My Descr
  • limitTo filter can be found even in ‘ng-repeat’ directive to limit the iteration.

orderBy

  • <li ng-repeat=”……. | orderBy:'(-)which'”>
  • order the repeating items in descending order if including ‘- (minus)’, or ascending order if not including it.

AngularJS – Directives(1)

Here, I am going to talk about the basic directives, “ng-show”, “ng-hide”, and “ng-repeat”.

 

ng-show

  • If you have a boolean variable in your model (or class whatever you call it), you can write code like the below.
    <div ng-show=”controller_name.model_name.boolean_value”>….</div>
  • the div area will be shown when the boolean_value is true, and it won’t if it is false.

 

ng-hide

  • ng-hide directive has almost the same effect as ng-show, but it makes your code a bit better readable.

 

ng-repeat

  • ng-repeat is a powerful directive.
  • just consider the code below
    <div ng-repeat=”item in controller_name.model_name”>
    <p> item.key1 </p>
    </div>
  • above code will iterate through all items in model_name by each one.
    then render <p> … </p> tags for every items.

 

ng-src

  • for <img> tag, image’s source is loaded before Angular’s expression is processed, so the <img> tag won’t work.
  • so AngularJS brings ‘ng-src’ directive for the <img> tag.
  • usage
    <img ng-src=”…….”/>

AngularJS – How to use Controller (basic)

How to create a new Controller

  • open up the “app.js” file
  • there should be the variable named “app”
  • write the code below
    app.controller(‘Controller_name’, function() {
    });

 

How to assign a data to a controller

  • declare a data below (not inside of the controller, but in the same depth level as the “app” variable)
    var data = { key1: value1, key1: “value2”, …….};
  • now inside of the controller write the code below
    app.controller(‘Controller_name’, function(){
         this.data_name_as_you_wish = data;
    });
  • now you could use values of the data in your web page (html)

 

How to use the data in HTML

  • add the directive named, “ng-controller” to a tag wherever you want to use the values included in the controller
    i.e) <body ng-controller=’Actual_Contoller_Name as Controller_Nickname’>
  • you can assign a nickname to your actual controller for easy use
  • now inside of the tag, we can write expressions
    key1’s value  is{{Controller_Nickname.data_name_as_you_wish.key1}}

AngularJS – How to create/add a module

How to create a new module.

  • create the “app.js” file if you don’t have
  • inside of the file, declare app variable like “var app;
  • write the code “app = angular.module(“module_name”, [dependencies,…]);

 

How to include a new module

  • open up a html file that you wish to use a angular module
  • inside of the <head> tag, include the “app.js” file
    <script type=”text/javascript” src=”app.js”></script>
  • declare the directive “ng-app” to a tag element you wish to use the new module
  • If you don’t know where, just put the directive to the <html> tag
    <html ng-app=”module_name”>

What if FA-LSP has reservable bandwidth?

Assuming.

A, B, C, D (Higher-Layer Nodes     PTN)

E, F (Lower-Layer Nodes     OTN)

  • path route to be established is A-B-C-D.
  • The traffic bandwidth needed is 1Gb.
  • There is no link between B and C.
  • There are inter-layer links between B and E, F and C.
  • ODU4 path is already established between E and F, but never used yet.
  • There are enough bandwidth and for traffic A-B-C-D in the inter-layer links.

 

Result

  • Between E and F, a new ODU2 trail inside of ODU4 can be created. (naming example is like m-odu4-5/1-2/1)
  • m-odu4-5/1-2/1 is advertised as a FA-LSP for the Higher-Layer LSP.
  • m-odu4-5/1-2/1 takes the PTN traffic (1Gb).
  • however, m-odu4-5/1-2/1 has remaining 9Gb bandwidth available.
  • the remaining bandwidth can be used for the future purpose.

What can RouterID & InterfaceID possibly be?

In LSP-DB and ERO,

there are ‘RouterID‘ and ‘InterfaceID‘ needed.

what are they for?

 

my guess

– RouterID is a kind of IP address to locate where a router is.

– InterfaceID is a kind of physical interface in a router/system.