代码之家  ›  专栏  ›  技术社区  ›  Patrick McDermott

在AngularJS控制器中用html编译表达式

  •  0
  • Patrick McDermott  · 技术社区  · 4 年前

    $uibModal 像这样:

    $scope.phoneNumber = '0111111111';
    
    var modalInstance = $uibModal.open({
        template: '<div class="modal-header d-flex flex-column align-items-center justify-content-center">\
                        <p class="font-h3 font-weight-medium">Please contact us on {{phoneNumber}}</p>                     
    
                    </div>',
        appendTo: undefined,
        controllerAs: '$ctrl',
        controller: ['$uibModalInstance', '$timeout', '$state', function($uibModalInstance, $timeout, $state){
    
            //LOGIC GOES HERE
    
       }]
    });
    

    当模态显示时,静态文本显示,但是表达式没有编译。

    问题

    0 回复  |  直到 4 年前
        1
  •  1
  •   stintaril    4 年前

    $scope.phoneNumber = '0111111111';
    
    var modalInstance = $uibModal.open({
        template: '<div class="modal-header d-flex flex-column align-items-center justify-content-center">\
                        <p class="font-h3 font-weight-medium">Please contact us on {{$ctrl.phoneNumber}}</p>                     
                   </div>',
        appendTo: undefined,
        controllerAs: '$ctrl',
        resolve: {
        phone: function () {
            return $scope.phoneNumber;
          }
        },
        controller: ['$uibModalInstance', '$timeout', '$state', 'phone', function($uibModalInstance, $timeout, $state, phone){
    
            //LOGIC GOES HERE
            this.phoneNumber = phone;
       }]
    });