如何在Angularjs中调用来自不同文件的服务

时间:2014-05-09 15:44:28

标签: javascript html5 angularjs model-view-controller

我知道在其他几个帖子中几乎回答了同样的问题但是我在调​​用不同文件中写入的服务时出现“未知提供程序”错误,然后是被调用者控制器函数。有人可以帮助我知道我做错了什么吗?这是我的代码

Controller.js

var mainApp = angular.module("mainApp", []);

mainApp.controller("PromoList", ['$scope', '$http', 'modelSerivce', function ($scope, $http, modelSerivce){
var serviceURL = modelSerivce.serviceURL();
console.log("from promolist controller: "+ serviceURL);}]);

Service.js

angular.module('mainApp').service('modelSerivce', function(){       
this.serviceURL = function()
{
    var serviceURL = “cofig.xml”;
    return serviceURL;
};});

1 个答案:

答案 0 :(得分:2)

您是否在.html文件中引用了Service.js