Sunday, November 22, 2015

Angular-1 Creating and using Controllers

MVVM

model is a personal property of a view (no seperate entity model created.
whatever user enters become model data )
request goes to view
view decides which controller to invoke

Modules
Views contains modules .
Module has controller(s)

Angular Directives

ng-app : to bind module in the view
        ng-controller: define your controller for your view with scope


<!DOCTYPE html>
<html ng-app="myapp">

  <head>
    <link rel="stylesheet" href="style.css">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0-beta.2/angular.min.js"></script>
    <script src="script.js"></script>
  </head>

  <body>
 
    <div ng-controller="HelloController as hello">
   
  {{2+2}}
  <h1>Hello {{hello.helloTo.Title}}</h1>

  </div>
   <div ng-controller="SalaryController">
     <h1>salary is  {{salary}}</h1>
   </div>
  <script>
    angular.module("myapp",[]).controller("HelloController",function($scope)
    {
      this.helloTo={};
      this.helloTo.Title="Supreet";
 
    })
 
     .controller("SalaryController",function($scope)
    {
      $scope.salary=10000;
 
    }
 
    );
 
  </script>
  </body>

No comments:

Post a Comment