【发布时间】:2015-12-08 22:51:57
【问题描述】:
我正在尝试将我的指令转换为使用 TypeScript 这是我目前所拥有的
'use strict';
module app.dashboard {
export class Safes implements ng.IDirective {
static $inject = ['$log', '$http', 'storeFactory'];
static instance($log, $http, storeFactory) {
return new Safes($log, $http, storeFactory);
}
templateUrl = '/app/shared/mocks/table.html';
restrict :string = 'A';
scope: any = {
title: '=',
rows: '='
};
link: (scope, element, attrs) => void;
constructor(private $log, public $http: ng.IHttpProvider) {
this.link = this._link.bind(this);
}
_link(scope, element, attrs) {
this.storeFactory.getSafes().then(success, failure);
function success(response) {
scope.safes = response.data.safes;
localStorage.setItem('safeCount', scope.safes.length);
this.$http.get('/app/dashboard/safes/safes.html', { cache: this.$templateCache }).success(function (tplContent) {
element.replaceWith(this.$compile(tplContent)(scope));
});
}
}
}
angular
.module('app')
.directive('safes', Safes.instance);
}
当我进入我的success 函数时,它会显示Cannot read property '$http' of undefined
我做错了什么不能访问$http?
【问题讨论】:
标签: angularjs angularjs-directive typescript