我app1.js
這樣angularJS文件
定義一些service
app1.js
angular.module('todoApp.services', []).factory('TodoService', function($http, $location) {
┊ return {
┊ ┊ send: function(url, par) {
┊ ┊ ┊ return $http.get(url, {
┊ ┊ ┊ ┊ params: par
┊ ┊ ┊ });
┊ ┊ },
┊ ┊ get_default_data: function($scope, url, par) {
┊ ┊ ┊ this.send(url, par).success(function(data) {
┊ ┊ ┊ ┊ $scope.data = data;
┊ ┊ ┊ });
┊ ┊ },
┊ ┊ change_status: function($scope, url, par) {
┊ ┊ ┊ this.send(url, par).success(function() {
┊ ┊ ┊ ┊ angular.forEach($scope.data, function(item) {
┊ ┊ ┊ ┊ ┊ if (item.id === par.sid) {
┊ ┊ ┊ ┊ ┊ ┊ item.status = par.status;
┊ ┊ ┊ ┊ ┊ }
┊ ┊ ┊ ┊ });
┊ ┊ ┊ });
┊ ┊ },
})
,我怎麼能在另一個.js
使用todoApp.services
文件?
我使用這樣
app2.js
angular.module('myapp', ['todoApp.services'])
它不工作,我該如何使用呢?
你說的「不行」是什麼意思?你有沒有包含你的service-js文件? – Rouby