简体   繁体   English

我无法将参数传递给模态Angular UI

[英]I cannot pass parameters to my modal Angular UI

I'm still new to Angular trying to understand its philosophy. 我对Angular尝试理解它的哲学仍然陌生。 I have two parameters: productSearched that's just a string, and a second parameter: agenceSearched , which has the following value when I try to display it in my modal: {id:'',nameAgence:null,adress:null} 我有两个参数: productSearched只是一个字符串,第二个参数是agenceSearched ,当我尝试以模式显示它时,它具有以下值: {id:'',nameAgence:null,adress:null}

I forgot to mention that I'm getting an injection exception as well: 我忘了提到我也遇到了注射异常:

Unknown provider: searchedAgenceProvider <- searchedAgence <- MapController

Here is my code: 这是我的代码:

myAppControllers
  .controller(
    'MapController',
    function($scope, mapService, $uibModal, $rootScope,
      commandService, searchedAgence, productSearched) {
      $scope.commandsearchedProduct = function(searchedAgence,
        productSearched, size) {
        console.log("rrrrrrrrrrrrr " + searchedAgence);
        console.log("aaaaaaaaaaaaa " + productSearched);
        $rootScope.modalInstance = $uibModal.open({
          animation: $scope.animationsEnabled,
          templateUrl: 'partials/cmdAgence.html',
          controller: 'MapController',
          resolve: {
            searchedAgence: function() {
              return $scope.searchedAgence;
            },
            productSearched: function() {
              return $scope.productSearched;
            }

          },
          scope: $scope,
          size: size
        });
      };
    });

Can anyone help me to find and understand the problem please? 谁能帮我找到并理解问题?

The problem is that your MapController and the modal instance have different scopes. 问题在于您的MapController和模式实例的作用域不同。

Change your resolve object to 将您的解决对象更改为

resolve : {
    searchedAgence : function(searchedAgence) {
        return searchedAgence;
    },
    productSearched : function(productSearched) {
        return productSearched;
    }
}

This should solve the problem. 这应该可以解决问题。

It seems that searchedAgence service is not available when injecting it in the MapController controller. 当在MapController控制器中插入searchedAgence服务时,似乎不可用。 Make sure you create this service first then only inject it. 确保先创建此服务,然后才注入它。 I am sure after it, it will work. 我敢肯定,它将成功。

Cheers!!! 干杯!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM