AngularJS匿名组件替换内部范围

时间:2017-02-02 09:42:03

标签: angularjs angular angularjs-scope ecmascript-6

您好我正在使用Angular和ES6,现在我想摆脱$scope,因为Angular2将不再使用它,我想创建futureprove代码,...这样可行:

let tab = this.tabManager.getArea.open({
        controller: ['$scope', function (scope) {

            console.log(scope);

            scope.close = function () {
                tab.close();
            }
        }],
        template: '<component-name on-close="close()" ...></component-name>'
    });


但是如何在不注入范围的情况下重写它,我想到了这样的事情:

    let tab = this.tabManager.getArea.open({
        controller: [class {

            constructor() {
               console.log('construct');
            }


            close() {
                console.log('close');
                tab.close();
            }
        }],
        template: '<component-name on-close="close()" ...></component-name>'
    });

但它似乎没有正常工作,调用了construtor,但是on-close绑定似乎不起作用。

1 个答案:

答案 0 :(得分:0)

1.6中的控制器类暴露$ ctrl对象,可以使用that.try一次访问“close()”