如何在指令模板中传递对象?

时间:2017-03-02 12:30:47

标签: angularjs

地方是一个对象。  create-itinerary是指令。我在模板传递create-itinerary指令中打开$ ubiModal并尝试传递一个对象place.But在指令中我得到[object object]。请帮助我。

$scope.showCreateItinerary = function(place) {
      var tpl = '<div create-itinerary trip-details="\'' + place + '\'"></div>';
      $uibModal.open({
        animation: true,
        ariaLabelledBy: 'modal-title',
        ariaDescribedBy: 'modal-body',
        template: tpl,
        controller: 'ModalCtrl',
        size: 'lg',
        backdrop: 'static',
        windowClass: "signup-popup abc"
      });
};

1 个答案:

答案 0 :(得分:1)

尝试使用resolve param:

$scope.showCreateItinerary = function(place) {
    $uibModal.open({
        animation: true,
        ariaLabelledBy: 'modal-title',
        ariaDescribedBy: 'modal-body',
        template: '<div create-itinerary trip-details="place"></div>',
        controller: 'ModalCtrl',
        size: 'lg',
        backdrop: 'static',
        windowClass: "signup-popup abc",
        resolve: {
            data: function () {
                return {
                    place: place
                }
            }
        }
    });
};

app.controller('ModalCtrl', function($scope, $modalInstance, data) {
   $scope.place = data.place;
});