相关疑难解决方法(0)

如何从控制台测试AngularJS服务?

我有这样的服务:

angular.module('app').factory('ExampleService', function(){
  this.f1 = function(world){
    return 'Hello '+world;
  }
  return this;
})
Run Code Online (Sandbox Code Playgroud)

我想从JavaScript控制台测试它并调用f1()服务的功能.

我怎样才能做到这一点?

angularjs angularjs-service

392
推荐指数
4
解决办法
11万
查看次数

AngularJS中的模块和命名空间/名称冲突

考虑以下jfiddle http://jsfiddle.net/bchapman26/9uUBU/29/

//angular.js example for factory vs service
var app = angular.module('myApp', ['module1', 'module2']);

var service1module = angular.module('module1', []);

service1module.factory('myService', function() {
    return {
        sayHello: function(text) {
            return "Service1 says \"Hello " + text + "\"";
        },
        sayGoodbye: function(text) {
            return "Service1 says \"Goodbye " + text + "\"";
        }
    };
});

var service2module = angular.module('module2', []);

service2module.factory('myService', function() {
    return {
        sayHello: function(text) {
            return "Service2 says \"Hello " + text + "\"";
        },
        sayGoodbye: function(text) {
            return "Service2 …
Run Code Online (Sandbox Code Playgroud)

namespaces collision angularjs angularjs-module

49
推荐指数
1
解决办法
2万
查看次数