无法在一个对话框中获取范围参数。为什么?

Cann't get scope parameters in ons-dialog. Why?

我认为这不是一个困难的问题,但出了点问题。我刚接触温泉 UI,我想创建一个对话框 window,我需要在其中输入一些参数。我不知道为什么它不起作用。这是我的 HTML:

<ons-template id="tippDialog">
<ons-dialog var="tippdialog" id="tippdialog" ng-controller="controllerName" cancelable>
    <div class="center">
        <h3>Tipp abspeichern</h3>
        <form action="saveTip.php">
            <ons-input id="tippa" type="number" placeholder="TipA" value=""></ons-input>
            <ons-input id="tippb" type="number" placeholder="TipB" value=""></ons-input>
            <p>{{tip_matchid}}{{userid}}</p>
        </form>
        <ons-button id="tippspeichern">Speichern</ons-button>
    </div>
</ons-dialog>

这就是我在控制器中所做的:

$scope.dialogs = {};

            $scope.tipDialog = function(match_id){
                tip_matchid = match_id;
                $scope.tip_matchid = tip_matchid;
                $scope.userid = userid;
                ons.createDialog("../dialogs/tippDialog.html", $scope).then(function(tippdialog){
                    $scope.dialogs[tippdialog] = tippdialog;
                    tippdialog.show();
                });
            }

在 Whosebug 中找到了其中的一些代码,但我发现没有任何帮助。希望可以有人帮帮我。谢谢!

找到解决办法了。认为这不是最好的方法,但你可以这样做:

$scope.dialogs = {};

            $scope.tipDialog = function(match_id, tipa, tipb){
                tip_matchid = match_id;
                ons.createDialog("../dialogs/tippDialog.html", $scope).then(function(tippdialog){
                    tippdialog._scope.tip_matchid = tip_matchid;
                    tippdialog._scope.userid = userid;
                    $scope.dialogs[tippdialog] = tippdialog;
                    tippdialog.show();
                });
            }

我想文档可以使用一些改进...

我还没有测试过,但我想这就是你要找的:

$scope.dialogs = {};

$scope.tipDialog = function(match_id){
    $scope.tip_matchid = tip_matchid = match_id;
    $scope.userid = userid;
    ons.createDialog("../dialogs/tippDialog.html", {parentScope: $scope}).then(function(tippdialog){
        $scope.dialogs[tippdialog] = tippdialog;
        tippdialog.show();
    });
}

重要的部分是{parentScope: $scope}

在当前的实施中,这是 Onsen 检查的 属性。
确实如此 ons.$compile(angular.element(element))(options.parentScope.$new())

所以基本上您的对话框具有您提供的对话框的同级范围。通过使用 {parentScope: $scope} 它变成了一个子作用域,我猜这就是你想要的。