17. Angularjs

home

Contents

Overview

// code <!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> <body> <div ng-app=""> <p>Input something in the input box:</p> <p>Name : <input type="text" ng-model="name" placeholder="Enter name here"></p> <h1>Hello {{name}}</h1> </div> </body> </html>

Routing, prepared in 12/02/2017

// ------------ index.html ------------------ <a href="main.html">go to main</a> // ------------ house1.html ------------------ <h4>house 1</h4> <h5>address: 123 Liberty Rd, Quincy, MA</h5> <p>4 bedrooms</p> <p>The price is ${{msg}}</p> // ------------ house2.html ------------------ <h4>house 2</h4> <h5>address: 555 Freedom Ln, Quincy, MA</h5> <p>3 bedrooms</p> <p>The price is ${{msg}}</p> // ------------ main.html -------------------- <!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script> <body ng-app="myApp"> <p><a href="#/!">Main</a></p> <p><a href="#!house1">House 1</a>&nbsp;&nbsp; <a href="#!house2">House 2</a> </p> <div ng-view></div> <pre> Quincy Property Company address: 987 Trusted Rd, Quincy, MA phone: 666-777-8888 </pre> <script> var app = angular.module("myApp", ["ngRoute"]); app.config(function($routeProvider) { $routeProvider .when("/main", { templateUrl : "main.html", }) .when("/house1", { templateUrl : "house1.html", controller : "house1Ctrl" }) .when("/house2", { templateUrl : "house2.html", controller : "house2Ctrl" }); }); app.controller("house1Ctrl", function ($scope) { $scope.msg = "36,500" }); app.controller("house2Ctrl", function ($scope) { $scope.msg = "30,100" }); </script> </body> </html>