Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Angular8中创建具有注释性函数的类_Angular_Anonymous Function_Anonymous Class - Fatal编程技术网

如何在Angular8中创建具有注释性函数的类

如何在Angular8中创建具有注释性函数的类,angular,anonymous-function,anonymous-class,Angular,Anonymous Function,Anonymous Class,我正在开发Angular 8应用程序,需要使用一个用于显示3D模型的库(JS+WASM)。为了在树表和三维模型之间进行交互,我需要在这个库中注册一个观察者 用于注册观察者(此库)的给定代码示例是用AngularJS编写的: 注册: $scope.RegisterSelectionObserver = function() { if ($scope.selectionObserver == null) { $scope.selectionObserver = new $sc

我正在开发Angular 8应用程序,需要使用一个用于显示3D模型的库(JS+WASM)。为了在树表和三维模型之间进行交互,我需要在这个库中注册一个观察者

用于注册观察者(此库)的给定代码示例是用AngularJS编写的:

注册:

$scope.RegisterSelectionObserver = function() {
    if ($scope.selectionObserver == null) {
        $scope.selectionObserver = new $scope.MySelectionClass();
        $scope.session.RegisterSelectionObserver($scope.selectionObserver);
    }
}
$scope.MySelectionClass = Module.SelectionEvents.extend("SelectionEvents", {
        __construct: function() {
            this.__parent.__construct.call(this);
            this.SetEventsFilter(Module.EVENTS_PICKS | Module.EVENTS_SELECTION);
        },

        OnSelectionBegin: function () {
            if ($scope.webglSettings.selectionLogging === 'YES') {
                console.log("OnSelectionBegin");
            }
        },
     });
export class ExtSelectionEvents{
    constructor(){
    }

    OnSelectionBegin(){
        console.log('OnSelectionBegin');
    }
}
const extSelectionEventsInstance = new ExtSelectionEvents();
session.RegisterSelectionObserver(extSelectionEventsInstance);
类定义:

$scope.RegisterSelectionObserver = function() {
    if ($scope.selectionObserver == null) {
        $scope.selectionObserver = new $scope.MySelectionClass();
        $scope.session.RegisterSelectionObserver($scope.selectionObserver);
    }
}
$scope.MySelectionClass = Module.SelectionEvents.extend("SelectionEvents", {
        __construct: function() {
            this.__parent.__construct.call(this);
            this.SetEventsFilter(Module.EVENTS_PICKS | Module.EVENTS_SELECTION);
        },

        OnSelectionBegin: function () {
            if ($scope.webglSettings.selectionLogging === 'YES') {
                console.log("OnSelectionBegin");
            }
        },
     });
export class ExtSelectionEvents{
    constructor(){
    }

    OnSelectionBegin(){
        console.log('OnSelectionBegin');
    }
}
const extSelectionEventsInstance = new ExtSelectionEvents();
session.RegisterSelectionObserver(extSelectionEventsInstance);
我的收养: 我试图用构造函数创建一个类,并将其传递给观察者注册,但出现了一个错误

我的自定义类:

$scope.RegisterSelectionObserver = function() {
    if ($scope.selectionObserver == null) {
        $scope.selectionObserver = new $scope.MySelectionClass();
        $scope.session.RegisterSelectionObserver($scope.selectionObserver);
    }
}
$scope.MySelectionClass = Module.SelectionEvents.extend("SelectionEvents", {
        __construct: function() {
            this.__parent.__construct.call(this);
            this.SetEventsFilter(Module.EVENTS_PICKS | Module.EVENTS_SELECTION);
        },

        OnSelectionBegin: function () {
            if ($scope.webglSettings.selectionLogging === 'YES') {
                console.log("OnSelectionBegin");
            }
        },
     });
export class ExtSelectionEvents{
    constructor(){
    }

    OnSelectionBegin(){
        console.log('OnSelectionBegin');
    }
}
const extSelectionEventsInstance = new ExtSelectionEvents();
session.RegisterSelectionObserver(extSelectionEventsInstance);
我的注册:

$scope.RegisterSelectionObserver = function() {
    if ($scope.selectionObserver == null) {
        $scope.selectionObserver = new $scope.MySelectionClass();
        $scope.session.RegisterSelectionObserver($scope.selectionObserver);
    }
}
$scope.MySelectionClass = Module.SelectionEvents.extend("SelectionEvents", {
        __construct: function() {
            this.__parent.__construct.call(this);
            this.SetEventsFilter(Module.EVENTS_PICKS | Module.EVENTS_SELECTION);
        },

        OnSelectionBegin: function () {
            if ($scope.webglSettings.selectionLogging === 'YES') {
                console.log("OnSelectionBegin");
            }
        },
     });
export class ExtSelectionEvents{
    constructor(){
    }

    OnSelectionBegin(){
        console.log('OnSelectionBegin');
    }
}
const extSelectionEventsInstance = new ExtSelectionEvents();
session.RegisterSelectionObserver(extSelectionEventsInstance);
错误:

$scope.RegisterSelectionObserver = function() {
    if ($scope.selectionObserver == null) {
        $scope.selectionObserver = new $scope.MySelectionClass();
        $scope.session.RegisterSelectionObserver($scope.selectionObserver);
    }
}
$scope.MySelectionClass = Module.SelectionEvents.extend("SelectionEvents", {
        __construct: function() {
            this.__parent.__construct.call(this);
            this.SetEventsFilter(Module.EVENTS_PICKS | Module.EVENTS_SELECTION);
        },

        OnSelectionBegin: function () {
            if ($scope.webglSettings.selectionLogging === 'YES') {
                console.log("OnSelectionBegin");
            }
        },
     });
export class ExtSelectionEvents{
    constructor(){
    }

    OnSelectionBegin(){
        console.log('OnSelectionBegin');
    }
}
const extSelectionEventsInstance = new ExtSelectionEvents();
session.RegisterSelectionObserver(extSelectionEventsInstance);
zone.js:703未处理的承诺拒绝:无法传递“[object]” 作为选择性事件*;区域:;任务:承诺;价值: BindingError{name:“BindingError”,消息:“无法传递”[object] 对象]“作为SelectionEvents*”,堆栈:“BindingError:无法传递 “[对象]”作为引用 ()“}消息:“无法通过 “[object]”作为SelectionEvents*”名称:“BindingError”堆栈: BindingError:无法将“[object]”作为SelectionEvents传递*↵
至少有一个错误。 ()↵
在new BindingError时(在createNamedFunction()时求值), :4:34)↵ 在ThrowBindingeror ()↵ 在 RegisteredPointer.NoncstNoSmartRrawPointerToWireType[as] toWireType] ()↵ 在 会话$RegisterSelectionObserver[作为RegisterSelectionObserver](评估) 在纽约_ (), :8:26)↵ 在 OverviewComponent.push../src/app/views/mechportal/overview/overview.component.ts.OverviewComponent.callback ()↵ 在↵ 在 ↵ at_loadPreferences ()↵ 在Object.LoadPreferences ()“proto:错误 BindingError:无法将“[object]”作为SelectionEvents传递* 至少有一个错误。() 在new BindingError(在createNamedFunction()处求值)时, :4:34)

摘要:

$scope.RegisterSelectionObserver = function() {
    if ($scope.selectionObserver == null) {
        $scope.selectionObserver = new $scope.MySelectionClass();
        $scope.session.RegisterSelectionObserver($scope.selectionObserver);
    }
}
$scope.MySelectionClass = Module.SelectionEvents.extend("SelectionEvents", {
        __construct: function() {
            this.__parent.__construct.call(this);
            this.SetEventsFilter(Module.EVENTS_PICKS | Module.EVENTS_SELECTION);
        },

        OnSelectionBegin: function () {
            if ($scope.webglSettings.selectionLogging === 'YES') {
                console.log("OnSelectionBegin");
            }
        },
     });
export class ExtSelectionEvents{
    constructor(){
    }

    OnSelectionBegin(){
        console.log('OnSelectionBegin');
    }
}
const extSelectionEventsInstance = new ExtSelectionEvents();
session.RegisterSelectionObserver(extSelectionEventsInstance);
该库要求OnSelectionBegin使用一个注释性函数,因为它正在为其创建一个命名函数


MySelectionClass中发生了什么?我如何翻译AngularJS类定义及其annonymous函数以使用Angular 8/库?

对此不确定,但您应该处理JS类:

export class ExtSelectionEvents extends SelectionEvents{
    constructor() {
      super();
    }

    OnSelectionBegin(){
        console.log('OnSelectionBegin');
    }
}

课堂选择事件是缺少的和平

在模块的全局delcaration(declare var Module:any)之后,我终于可以扩展SelectionEvents类并实现我的方法

AngularJS和AngularJS实现之间的唯一区别是作用域不同。在AngularJS中,它被绑定到控制器的作用域,现在它处于全局作用域

   const MyEventsClass = Module.SelectionEvents.extend("SelectionEvents", {

  __construct: function () {
    this.__parent.__construct.call(this);
    this.SetEventsFilter(Module.EVENTS_PICKS | Module.EVENTS_SELECTION);
  },

  OnSelectionBegin: function () {
      console.log("OnSelectionBegin");
      console.dir(this);
  }
});

session.RegisterSelectionObserver(new MyEventsClass());

不幸的是,当我尝试扩展选择事件时,我遇到了一个引用错误:SelectionEvents未定义。@BenjaminSteiner您应该找到它的来源,因为在AJS中,它们是从它扩展而来的。感谢您对SelectionEvents扩展的提示。让它与SelectionEvents的扩展一起工作。此类仅在全局范围内可用。所以我将它声明为Module,并可以像这样初始化这个类:const myeventclass=Module.SelectionEvents.extend(“SelectionEvents”,{this.\uu-construct:function(){this.\uu-parent.\uu-construct.call(this);this.SetEventsFilter(Module.EVENTS_-PICKS | Module.EVENTS\u-SELECTION);},OnSelectionBegin:function(){console.log(“OnSelectionBegin”);}};没问题,很高兴我能帮上忙!