About the use of preliminary AngularJS

Mvc mode using a basic Dian (<Script the src = "angular.min.js"> </ Script>)
  Model: data, two-way binding, global universal, i.e. Angular variable format $ scope.xx

  view: presentation of data, Html instruction (Directive) combined 

  controller: the operation data, the operation is the use of function, to achieve the CRUD

Two Dian create a model, controller and service

   1.var app = angular.model ( "Custom block name", [ "application modules"])

   2.app.service ( "custom service name", function ($ http)) {this. Method Name = function (parameter) {return service link, such as interaction with back connection}}

        示例:  app.service("brandService",function ($http) {

                this.findAll=function(){

                 return $ htttp.get ( "interactive url")}

  3.app.controller ( "Custom controller name", function ($ scope, the server name)) {control layer, the operation data}

        Example: $ scope.findAll = function () {

            Service Name. Method name () a .success ( function (the Response) {

                $scope.list=response;}

  4. Layer js are defined in different files, but if there is a dependency, attention vertical position when introducing the relevant page js file. The module defined app js file controller should be located in upper and service.

Wed and some simple instructions

  1.ng-app = "module name" module enables a statement in the body tag, the identification will be resolved in the interior of the angular instruction tag

  2.ng-controller = "Controller Name" in the body tag, content informing the body is controlled by the controller

  3.ng-init = "eg: name = .." is used to initialize the variable 

  4.ng-model = "variable" variable defined in the internal label, two-way binding, in the controller

  5.ng-repeat = "set in the variable name" through the data, as defined set out in the controller

  6. $ event status label, which is passed as a parameter to the controller, such as checkboxes selected $ event.target.checked

Four Dian controller inheritance

  Pseudo inheritance, the two universal $ scope to achieve the effects of a succession.

  Format: $ controller ( "controller inherited", {$ scope: $ scope})

  

Guess you like

Origin www.cnblogs.com/hanpi/p/11627560.html