angular--Custom Service--passing parameters in multiple controllers Factory+service+provider

Source: Internet
Author: User
<! DOCTYPEHTML> <HTMLng-app="MYAPP"> <Head> <Metacharset="UTF-8"> <title>title</title> <Scriptsrc="Js/angular.min.js"></Script> </Head> <Bodyng-controller="My"> <spanng-bind="name1"></span> <spanng-bind="name2"></span> <spanng-bind="Name3"></span> </Body> <Script>varapp=angular.module ("MYAPP",[]);app. Controller ("My",["$scope","Serv","Serv2","Serv3",function($scope, S1,S2,S3) {$scope.name1=S1; $scope.name2=S2; $scope.Name3=S3; }])///factory method to implement custom services in the project is more frequent,//in its simple syntax and use of popularapp. Factory ("Serv",function() {var_v="The first kind of factory";return_v;
})//service mode implementation of custom services, the returned data must be a JSON object,//In some projects in order to standardize the return value of the data, the Convention uniformly use the object for processing. Service is more consistent with this specification, so use more frequentlyapp. Service ("Serv2",function() {return{_V2:"Second Service"}; })//provider custom service, used more inside the angular framework,//Because the code operation more tends to lower the level of code readability,//For the General project development has some difficulty, so project development uses lessapp. Provider ("Serv3",function() { This. $get =function() {return{_v3:"The Third Kind of provider"}; }}) </Script> </HTML>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.