如何通过angularjs将值传递给一个控制器到另一个控制器?

如何通过angularjs将值传递给一个控制器到另一个控制器?

问题描述:

Here the Sample Link如何通过angularjs将值传递给一个控制器到另一个控制器?

我试着实现模态窗口。我从网上找到一些样本,并且实施了。

在这里我添加了模态窗口的示例文件。这工作正常。

我确实需要的是在打开模型窗口时我会调用这个函数。

$scope.callType = {}; 
$scope.dataFormDialog = function (id) { 
    $scope.callType.id = id; 
    exDialog.openPrime({ 
     scope: $scope, 
     template: '_Product.html', 
     controller: 'productController', 
     width: '450px', 
     //animation: false, 
     //grayBackground: false    
    }); 
}; 

这里我从sampleController调用_Product.html和productController。

模态窗口从sampleController那一次调用。

如何将sampleController的$ scope值传递给productController?

任何一个可以帮助我在这?...

+0

您可以使用服务这一点。 –

+0

你能解释一下吗? @ hadiJZ –

+1

可能会帮助你http://*.com/questions/20181323/passing-data-between-controllers-in-angular-js –

试试这个

$scope.dataFormDialog = function (id) { 
    $scope.callType.id = id; 
    exDialog.openPrime({ 

     template: '_Product.html', 
     controller: 'productController', 
     width: '450px', 
     resolve: { 
        Scopevariable: function() { 
        return $scope; 
        } 
     //animation: false, 
     //grayBackground: false    
    }); 
}; 


app.controller('productController', ["Scopevariable", 
function (Scopevariable) 
{ 
    // use Scopevariable 
}]); 

传递一个范围NG-对话的控制器有物业的范围,你可以与任何对象赋给它,该对象及其可用于对话框控制器的属性。

实施例 -

$scope.value = true; 
ngDialog.open({ 
    template: 'externalTemplate.html', 
    className: 'ngdialog-theme-plain', 
    scope: $scope 
}); 

<script type="text/ng-template" id="externalTemplate.html"> 
    <p>External scope: <code>{{value}}</code></p> 
</script> 

在上面的例子中你在$范围的值的对象。在传递整个$ scope的对话框中,可以访问externalTemplate.html中$ scope的所有属性。

详细检查这些ng-dialog scope