Giter Site home page Giter Site logo

chi-angular-intro's Introduction

Chi Angular Intro

Notes

  • We are currently using Angular 1.6.
  • Angular 2 is NOT backwards compatible.
  • Google is supporting Angular 1 & 2 in parallel
 Angular | Angular       
--------------------
   1.0   |    2
   1.1   |    3
   1.2   |    4  <- Beta
   1.3   |    
   1.4   |  
   1.5   |  
   1.6   |        

Setup

  • npm install angular --save
  • Copy angular.js into the root directory

Example

Directives

Directives are subsets of functionality we put into our elements.

First, create an index.html file.

<!DOCTYPE html>
<!-- Most basic Angular app -->
<html ng-app="myApp"> <!-- Angular has full control over the page -->
  <head>
    <meta charset="utf-8">
    <title></title>
    <script type="text/javascript" src="angular.js"></script>
    <script type="text/javascript" src="client.js"></script>
  </head>
  <body>
    <!-- 2 Way Binding Example -->
    <!-- Similar to... var intro = what you type -->
    <input type="text" ng-model="intro">
    <!-- intro is an expression, could be {{intro + " meow"}} or {{ 7 + 2 }} -->
    <p>{{intro}}</p>
  </body>
</html>
  • ng-app Centralized implementation wrapping the entire experience
  • ng-model

Now let's create a new file client.js and source it in.

// First param links to <html ng-app="myApp">
// [] is the dependency injection array, what services do we need?
var myApp = angular.module('myApp', []); // Leave array empty for now

// Configure the app by creating a controller
myApp.controller('BaseController', ['$scope', function($scope){
  // $scope is the scope of this function but it's special. It allows
  // us to create variables that are data bound to the section of the
  // controller that it exists.

  $scope.hello = 'Hello World';
}]);

// Scope the controller to a set of elements

Update the HTML

<div ng-controller="BaseController">
  <p>{{hello}}</p>
</div>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.