<! 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)