Ionic preparation of angular basic ——— services provider and factory (9)

Source: Internet
Author: User

<! DOCTYPE html>

We can create the service in config again, or create it directly in module, use provider to create the This.get () anonymous function, and factory can return the string or object directly, and suggest to return based on the object.

So it won't be too messy, and of course there's a better, more intuitive way to create it.

<! DOCTYPE html>

The above case introduces an external JS, which is dedicated to defining various services

/** * Created by Administrator on 2016/3/28. */var service=angular.module (' MyService ', []) service.service (' Getmessagefactory ', function () {    var service={};    Service.getmessage=function () {        return "This is the JS service for external files";    }    return service;}) Service.service (' GetMessageFactory1 ', function () {    var service={};    Service.getmessage=function () {        return "This is the JS service for external files 1";    }    return service;}) Service.service (' GetMessageFactory2 ', function () {    var service={};    Service.getmessage=function () {        return "This is the JS service for external files 2";    }    return service;})

Mudule in HTML Remember to introduce dependencies before you introduce dependencies of course you have to make sure that your service.js has been introduced into the page.

  

Ionic preparation of angular basic ——— services provider and factory (9)

Related Article

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.