search

Home  >  Q&A  >  body text

angular.js - How many parameters does a controller in AngularJs have?

var app=angular.module("myApp",[]).controller("myController",function("这里有多少个参数"){})
phpcn_u1582phpcn_u15822859 days ago587

reply all(4)I'll reply

  • 天蓬老师

    天蓬老师2017-05-15 16:55:06

    Depending on how many parameters you inject, the general usage is as follows:

    var app = angular.module('app', []);
    app.controller(function($scope, $http){
        //那这个时候就只有这两个参数,这个东东在angular里叫做依赖注入。并不是默认行为,二是需要你来自己制定的,所以是多少个,就看你自己怎么用了
    });
    

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-15 16:55:06

    var app=angular.module("myApp",[]);
    app.controller("myController",['$scope','aService',...,function($scope,aService,...){
        //可以注入你写的factory,provider等等
    }]);
    

    • The first parameter of the controller is the name, followed by an array. The front of the array is the content to be injected, which can be n. The last parameter is a function. The number of parameters of the function must also be n. It must be the same as the content to be injected. One-to-one correspondence
    • This is how dependency injection is implemented

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-15 16:55:06

    console.log(arguments) Take a look~

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-15 16:55:06

    can be n,

    jsvar app=angular.module("myApp",[])
    .controller("myController",['$scope','aService',...,function($scope,aService,...){
        //可以注入你写的factory,provider等等
    }])
    

    reply
    0
  • Cancelreply