Typescript中为angular指令输入错误的服务对象
Service object wrongly typed for angular directive in Typescript
下面是一个angular指令的typescript:问题出在被注入的服务"datcontext"上。调试器显示构造函数中的数据上下文是一个WINDOW对象,而不是作为服务创建的数据上下文对象。因此,在范围内。viewRecord函数,datacontext.cancelChanges()函数显然是未定义的——因为它不是WINDOW对象的一部分。这可能是一些奇怪的范围问题,我只是没有得到,但我对如何调试这个感到茫然。任何见解将是最感激的。谢谢。
module app {
export interface IEditButtonGroup {
...
}
export interface IEditButtonScope extends ng.IScope {
...
}
export class PrxEditButtonGroup implements IEditButtonGroup {
public static $inject: Array<string> = [
"datacontext"
];
constructor(
public datacontext: IDataContext, <---- datacontext HERE is typed as a WINDOW object
public directive: ng.IDirective = {}) {
directive.templateUrl = "app/directives/templates/editbuttongroup.html",
directive.restrict = 'E';
directive.link = (scope: IEditButtonScope, element, attr) => {
scope.isEditing = false;
scope.isAdding = false;
$("form.disabled").find("input:not(:disabled), select:not(:disabled), textarea:not(:disabled)").prop("disabled", true);
scope.editRecord = () => {
$("input, select, textarea").removeAttr("disabled");
scope.isEditing = true;
scope.afterEdit();
}
scope.viewRecord = (afterCancel: boolean) => {
datacontext.cancelChanges(); <--- HERE TOO! Debugger says datacontext = WINDOW object
scope.isEditing = scope.isAdding = false;
$("form.disabled").find("input:not(:disabled), select:not(:disabled), textarea:not(:disabled)").prop("disabled", true);
scope.afterAdd();
}
}
return <any>directive;
}
}
}
错误似乎是在你注册这个指令的地方。确保它像这样:
mymodule.directive('prxEditButtonGroup',app.PrxEditButtonGroup )
相关文章:
- 如何将javascript对象作为参数传递到c#web服务中
- 对象未从Ionic服务正确返回
- 为什么Angularjs服务返回的是字符数组而不是对象数组
- 关注点,装饰者,演示者,服务对象,帮助者-帮助我理解他们
- 角度控制器不绑定服务对象属性 ng-repeat
- 表示不将对象从服务发送到 API 控制器
- 为什么从 Angular 服务中的对象中删除此元素不起作用
- 将工厂/服务对象隔离到单个元素's指令
- 利用谷歌分析API与Javascript -生成服务对象
- Angular,如何停止对服务对象的跟踪
- AngularJS:服务对象为空
- 将指向服务对象属性的指针/引用添加到$scope变量
- Typescript中为angular指令输入错误的服务对象
- 在异步(ajax)调用后将服务/对象注入控制器
- 更新angular.js服务对象,无需扩展/复制
- SP服务-对象不'我不支持这种方法
- 每次测试后重置服务对象
- 在angularjs中,认证服务对象在刷新时会丢失页面
- AngularJS:如何观察服务对象
- 将Web服务对象列表转换为数组的数组