Angularjs

Angular JS Modules

Moduler is a container and controller resides in Module.

Working with Modules:

  • Create  module with a name
  • Register your controllers with module
  • Ask angular to use your mdule with ng-app

Example:


<!DOCTYPE html>
<html ng-app="techkatakviewer">
  <head>
    <script data-require="[email protected]*" data-semver="1.3.0-beta.5"
    src="<a href="https://code.angularjs.org/1.3.0-beta.5/angular.js%22%3E%3C/script">https://code.angularjs.org/1.3.0-beta.5/angular.js"&gt;&lt;/script</a>&gt;
    &lt;link rel="stylesheet" href="style.css" /&gt;
    &lt;script src="script.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;h1&gt;"Hello Angular JS!!"&lt;/h1&gt;
    &lt;div ng-controller="MyController"&gt;
      {{message}}
    &lt;/div&gt;   
    &lt;div ng-controller="MyController1"&gt;
      &lt;div&gt;First name: {{person.firstname}}&lt;/div&gt;
      &lt;div&gt;Last name: {{person.lastname}}&lt;/div&gt;
      &lt;div&gt;welcome {{person.firstname}} {{person.lastname}} &lt;/div&gt;
    &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;


Function();
{
  var app=angular.module("techkatakviewer",{});
var MyController = function($scope)
{
  $scope.message = "hello, Angular !!";
};
var MyController1 = function($scope)
{
 var person =
{
 firstname: "Tech",
 lastname: "Katak"
};
$scope.person=person;
};
app.controller("MyController",MyController);
}

© 2015, www.techkatak.com. All rights reserved.