The previous page was so ugly that I introduced the bootstrap.css and repaired the style, such as:
(Link: http://www.live086.cn/angularjs/#/phones)
is not feel much better, here I in the original Phone.json inside add the figure of the picture, so Phone.json becomes:
[ {"id": 1, "name": "Xioabin", "number": "18824863982", "Age": "Thumb": "Image/nan.jpg"}, .... ]
Images can be found on their own
The controller file does not change, the template file added Bootstrap.css, there is a significant change, the code is as follows:
<!doctype html> for= "Select" > Shang: </label><select name= "Select" id= "select" ng-model= ' Order ' class= "Form-control" >< Option value= "name" > Name </option><option value= "Age" > Ages </option> </select></div> & Lt;div class= "Form-group" ><label for= "Search" > Search </label><input id= "search" name= "search" type= "text" ng-model= ' query ' class= "Form-control"/ ></div> </form> <!--iterators--<table class= "table" > <tr> <t H class= "Text-center" > Avatar </th> <th class= "Text-center" > Nickname </th> <th class= "Text-ce Nter "> Phone number </th> <th class=" Text-center "> Age </th> </tr> <tr ng-repeat= ' Phone in Phones | Filter:query | Orderby:order ' > <td class= "text-center" ><a href= "#/phones/{{phone.id}}">ng-src= "{{phone.thumb}}" style= "width:40px;height:40px;border-radius:50%" alt= "Hahah" ></a> <!-- Add NG-SRC to identify the data--></td> <td class= "Text-center" >{{phone.name}}</td> <td class= "t Ext-center ">{{phone.number}}</td> <td class=" Text-center ">{{phone.age}}</td> </tr& Gt </table> </div> </body>
Other content does not change, but because the JSON file inside we add the character's picture, I need to use NG-SRC to bind the picture path, this cannot use the original SRC, otherwise src= "{{phone.thumb}}" Cannot load the picture resource.
Have you noticed why the "#/phones/{{phone.id}" is going to be written, so this involves routing configuration and how to implement a jump between multiple views, so we made a change to the whole learning project: The directory is as follows:
Here, as we said before, the controller files, service files, filters, instructions are written separately, index.html is the layout of this Learning project template, can also be understood as a root template, all views (other template tpls) will be loaded through the route to this template Ng-view inside, the code is as follows:
<!doctype html> <script src=" Lib/angular-route.js "></script <script src= "app.js" ></script> <script src= "Controllers.js" ></script> <link rel= "stylesheet" href= "Bootstrap.min.css" > ng-view ></div> </body>
App.js, first through Angular.module (' Phonecat ', [' ngroute ', ' Phonecontroller ']), building modules, remembering ng-app= "Phonecat", For an HTML page want to have multiple Ng-app, can angualr.bootstrap (doucment,[' Phonecat ',...]); The "Ngroute" service needs to be injected here, and Angular-route.js must also be introduced,
var phonecat = angular.module (' Phonecat ', [' Ngroute ', ' Phonecontroller ']) ; // [.... Dependency Injection phonecat.config ([ ' $routeProvider ', function ($routeProvider) {$routeProvider. When ( "/phones", {templateurl: "tpls/phones-list.html", Controller: "Phone-list-controller" }). When ( "/phones/:p Honeid", {templateurl: "tpls/phones_detail.html", Controller: "Phone-detail-controller" Span style= "color: #000000;" >}). Otherwise ({redirectto: "/phones"
//The configuration here means: Domain + project directory +/#/phones will then jump to tpls/ Phones-list.html, the controller being processed is phone-list-controller
domain + project directory +/#/phones/id then it jumps to tpls/phones_detail.htmland handles the controller as Phone-detail-controller
Use config to inject the $routeprovider service (only if the Ngroute module is introduced), when(path, Route) and otherwise (params) To define the route,
When (path,route) path: The URL of the access, the route is an object, inside the controller (corresponding to controllers),Controlleras, Templateurl (path to template), Tempalte, Redirectto
otherwise (params), is the match when there is no corresponding route, what to do with it! {redirectto: "/phones"} jumps to/phones
Phone-list.html
<div ng-controller= "Phone-list-controller" > <form class= "form-inline" style= "margin:20px 0;" > <div class= "Form-group" ><label for= "Select" > Shang: </label><select name= "Select" id= "select" ng-model= ' Order ' class= "Form-control" >< Option value= "name" > Name </option><option value= "Age" > Ages </option> </select></div> & Lt;div class= "Form-group" ><label for= "Search" > Search </label><input id= "search" name= "search" type= "text" ng-model= ' query ' class= "Form-control"/ ></div> </form> <!--iterators--<table class= "table" > <tr> <th CLA ss= "Text-center" > Avatar </th> <th class= "Text-center" > Nickname </th> <th class= "Text-center" > Phone number </th> <th class= "Text-center" > Age </th> </tr> <tr ng-repeat= ' phone In Phones | Filter:query | Orderby:order ' > <td class= "text-center" ><a href= "#/phones/{{phone.id}}" ></a> <!--add NG-SRC identify the bound data-- </td> <td class= "Text-center" >{{phone.name}}</td> <td class= "Text-center" >{{phon e.number}}</td> <td class= "Text-center" >{{phone.age}}</td> </tr> </table> </div&Gt
Phone-detail.html
This is the details page for Phoneid {{Phoneid}}
Controllers.js
varPhonecontroller = Angular.module (' Phonecontroller '), []); Phonecontroller.controller ("Phone-list-controller", [' $scope ', ' $http ',function($scope, $http) {$http. Get ("Phone.json"). Success (function(data, status, headers, config) {if(status==200) {$scope. phones = dATA; } console.log (Status+ "," +headers+ "," +config); //Alert (json.stringify (data)); }); $scope. Order= ' name ';}]); Phonecontroller.controller ("Phone-detail-controller", ["$scope", '$routeParams‘,function($scope, $routeParams) {$scope. Phoneid=$routeParams. Phoneid;
$routeParams is the need to introduce Ngroute module, to get passed the parameters Phoneid}])
Study Note-angularjs (Fri)