我想连接一个简单的数据服务来从服务器检索http调用数据。我正在使用TypeScript来编写代码。出于某种原因,我无法获得服务来查看其依赖关系。 这里是服务它是由打字稿 由angularjs工厂创建的数据服务不依赖
var app = angular.module('app',[]);
app.constant('baseUrl', 'http://localhost:63342');
//This follows the pattern created by Typescript
var myService = function(){
function myService($http, baseUrl){
this.$http = $http;
this.baseUrl = baseUrl;
this.http = typeof this.$http;
this.url = typeof this.baseUrl;
}
myService.$inject = ['$http', 'baseUrl'];
return myService
}
app.factory('myService', [
'$http', 'baseUrl',
myService
]);
app.controller('myCtrl',
['$scope', 'myService',
function($scope, myService){
$scope.httpType = myService.http;
$scope.urlType = myService.url}]
);
产生的方式,当我运行的代码在本地p标签得到了NG-绑定属性在他们设置。但是,当然,他们没有任何东西。当我分配$ scope分配时,myService是可用的,它有$ inject变量,但没有其他4个变量。 Typescript和angular的可用示例非常薄。必须有一些基本的东西我做错了。
Here is a fiddle with the code.我不知道为什么小提琴没有跨越范围变量。
也忽略使用还有其他网址并重新替换你自己的baseurl。 – ossek
我现在已经创建了3个示例,从头开始计算出哪里出错,其中两个服务现在正在获取其依赖关系,但控制器没有获得对服务的依赖,所以我现在可能会发布代码,看看我回来了。 – pthalacker