首页 > 解决方案 > 无法将数据传递给AngularJS中组件内的控制器

问题描述

我有以下组件

componentsModule.component('detailComponent', {
    templateUrl: 'detailTemplate.html',
    scope: {},
    bindings: {
        textParam: '='
    },
    controller: ['$mdDialog',  function($mdDialog) {
      this.textParam // this is undefined always
   }]
});

我正在像这样从其他控制器的对话框中加载模板

$scope.textParam = tParam;
const parentEl = angular.element(document.body);
$mdDialog.show({
      template: '<detail-component text-param="$scope.textParam"></detail-component>',
      ariaLabel: 'detailComponentDialog',
      parent: parentEl
}).then((savedDatails) => {});

如果我使用绑定,@那么我会$scope.textParam在我的控制器中得到一个字符串,this.textParam但是如果我将绑定设置为<or=然后我会得到 undefined

标签: angularjsangularjs-controllerangularjs-componentsmddialog

解决方案


推荐阅读