Angular JS 将 $scope 传递给模态

Angular JS Passing $scope to Modal

http://jsfiddle.net/dwmkerr/8MVLJ/

我正在尝试从上面的示例中进行实验。我的问题是模态似乎无法从调用它的 $scope 中读取任何内容。

Javascript

$scope.sampleTest = "SAMPLE TEXT"; // additional code
$scope.show = function() {

    ModalService.showModal({
        templateUrl: 'modal.html',
        controller: "ModalController"
    }).then(function(modal) {
        modal.element.modal();
        modal.close.then(function(result) {
            $scope.message = "You said " + result;
        });
    });
};

HTML

<p>It's your call...{{sampleText}}</p>

模态只显示 "It's your call..." 而不是 "It's your call... SAMPLE TEXT"

这里有什么我遗漏的吗?

由于模态有自己的控制器(与调用模态的控制器分开),您需要将所需的任何变量传递到模态的解析函数中。

然后在模态控制器中,您需要将已解析的对象添加到作用域中,以便它能够在模态视图中绑定

希望对您有所帮助。