如何在 angularjs 中将值传递给一个控制器到另一个控制器

How to pass the value to one controller to another controller in angularjs?

本文关键字:控制器 一个 另一个 angularjs 值传      更新时间:2023-09-26

这里是示例链接

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

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

我真正需要的是打开模型窗口时,我将调用此函数。

$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和产品控制器。

模式窗口 从示例控制器调用那个时间。

如何将 sampleController 的$scope值传递给产品控制器?

任何人都可以帮我吗?...

试试这个

$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-dialog的控制器,可以使用属性范围为其分配任何对象,并且可以在对话框的控制器中使用该对象及其属性。

例-

$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 的值对象。在对话框中传递整个$scope因此可以访问外部模板.html中$scope的所有属性。

有关详细信息,请查看这些 ng 对话框范围