1
得到返回從服務價值這是模塊和控制器代碼如何angularjs
var app = angular.module('apApp',[]);
app.controller('apCtrl', ['$scope','$http','getPopByBranch',function($scope, $http,getPopByBranch)
{
$scope.greeting = 'Hola!';
console.log(getPopByBranch.test) ;
}]);
var boot_apApp = document.getElementById('apApp');
angular.element(document).ready(function() {
angular.bootstrap(boot_apApp, ['apApp']);
});
這是保存在單獨的js我的服務代碼文件
angular.module('apApp').factory('getPopByBranch', function($http){
var pops = {};
pops.test = function(){ return "Hello";};
//i want value of second function also
//pops.test = function foo(){ return "Bye";};
return pops;
});
輸出在控制檯
function(){ return "Hello";}
問題是,我只想你好或返回一些價值。
@MartijnWelker - 那隻能看標記後說。另外,我相信OP能夠記錄該功能,然後OP能夠引導應用程序。調用函數時只是缺少OP – nikhil