首页 > 解决方案 > angularjs继承objectprototype只能是对象或者null

问题描述

我认为这将是一个简单的基类和子类任务,但这个错误正在抛出我。

我创建了一个这样的基类:

module A.B.C {

   export class instructionBase {

      constructor(
      var1: class1,
      var2: class2,
      ...etc for 10 injected classes) { //init code }

      method1(){}

      method2(){}
   }
}

我继承的类是这样的:

namespace A.B.C {

   export class instructionComponent extends instructionBase {

      static $inject = ["", "", ""...for 10 times]

      constructor(
         var1: class1,
         etc for 10 times) {

         super(var1, for 10 times)
         }
   }

   // Register the component
   angular.module("myApp.abc")
    .component("instructioncomponent", {
        templateUrl: "/.../instruction.component.html",
        controllerAs: "vm",
        transclude: true,
        controller: instructionComponent 
    });

}

在运行时我收到此错误:

未捕获的类型错误:对象原型可能只是一个对象或空:未定义在 setPrototypeOf () at __extends (someOtherClassICreatedALongTimeAgo.js:6) at instrumentComponent.ts:4 at ABC (instrumentComponent.ts:4) at ABAB(instrumentComponent.ts:45 ) 在 A (instrumentComponent.ts:45) 在 instrumentComponent.ts:45

令我感兴趣的是,在错误的第 6 行,命名空间部分重复了两次。我是否有意外的循环引用?

从错误中查看这个类(someOtherClassICreatedALongTimeAgo),它还扩展了一个基类,所以我必须在某处交叉电线。

TIA

标签: angularjs

解决方案


最有可能在您尝试扩展instructionBase它时是undefined. 那将是我的猜测。如果您想确定这一点,请尝试将其放在同一个文件中


推荐阅读