2017-03-02 49 views
1

地方是一個對象。 create-itinerary是指令。我在模板中打開$ ubiModal傳遞create-itinerary指令並嘗試傳遞一個對象的地方。但是在指令中我得到了[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" 
     }); 
}; 
+0

你使用AngularUI? – mvermand

+0

也許這有助於:http://stackoverflow.com/questions/18924577/scope-issues-with-angular-ui-modal – mvermand

回答

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; 
}); 
+0

我需要創建行程指令的地方數據 –

+0

@AyanSundarJana尼斯,這樣做。 – lin

+0

其實這就是問題所在。我可以將變量傳遞給模態控制器。但正如你所看到的,我的模態模板是動態的,它是一個隔離範圍的指令。因此,即使我將對象傳遞給模態控制器,該指令也無法訪問它。我需要以某種方式將對象傳遞給指令。 –

相關問題