我正在尝试将我的Angular 1.5代码重写为ES6。我正在使用import angular from 'angular';
import ngDialog from '../libraries/ng-dialog';
const template = `<div>
<button ng-click="ctrl.openTheDialog()">Click Me</button>
</div>`;
class MyController {
constructor($scope) {
'ngInject';
this.$scope = $scope;
}
openTheDialog() {
ngDialog.open({
template: templateUrl,
scope: this.$scope
});
}
}
angular.module('myApp', ['ngDialog'])
.component('myComponent', {
template: template,
controllerAs: 'ctrl',
controller: MyController
});
并且我正在导入它但不将其注入控制器,因为我试图使其成为模块本身的依赖项。我有以下代码:
open
单击按钮时,出现{% url 'admin:index' %}
不是函数的错误消息。我不确定我在哪里弄错了。有人可以帮助指出错误吗?谢谢!
答案 0 :(得分:0)
原来你只需要将ngDialog设置为构造函数中的属性:
constructor($scope, ngDialog) {
this.ngDialog = ngDialog;
...
...
}
openTheDialog() {
this.ngDialog.open({
...
});
}