AngularJS Basics

0

Category :

1) Angular Directive = ng-app

2) Access Angular Model through controllers

3) $scope is Angular Model

4) ng-controller directive sets js function name to use as controller for a portion of page, different portions of the page could have diff controllers.

5) Setting ng-app="nameApp" prevents polluting of the global namespace:
 
 <html ng-app="nameApp">
   <head>
     <meta charset="utf-8">
     <title>Angular.js Example</title>
     <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js"></script>
     <script>
       var nameApp = angular.module('nameApp', []);
       nameApp.controller('NameCtrl', function ($scope){
         $scope.firstName = 'John';
         $scope.lastName = 'Smith';
       });
     </script>
   </head>
   <body ng-controller="NameCtrl">
     First name:<input ng-model="firstName" type="text"/>
     <br>
     Last name:<input ng-model="lastName" type="text"/>
     <br>
     Hello {{firstName}} {{lastName}}
   </body>
     </html>
    
6) Could have multiple Angular apps running on the same page.







my thanks to:
https://github.com/curran/screencasts/tree/gh-pages/introToAngular

0 comments:

Post a Comment