我做了一个简单的例子,其中使用了 resolve 关键字。但我不知道它有什么用。让我解释一下这个例子。我有一个按钮和文本字段。什么都可以我在文本字段上书写,然后按单击它会打开弹出屏幕,其中包含与文本字段中写入的相同文本。 所以我的问题是解决是什么意思?其次,textValue:函数调用从哪里开始?
resolve: {
textValue:function(){
return $scope.textValue;
}
}
其次,如果我需要反之亦然,我怎样才能实现这一点?换句话说,如果我单击按钮打开弹出屏幕,在文本字段上写任何内容,然后单击提交按钮,它会在输入字段上显示文本。?这是如何实现的可以实现吗?
这里是笨蛋 http://plnkr.co/edit/ulxiqEU62NuMWBMLWqkr?p=preview 如何更改值
最佳答案
我已经更新了代码,可以以两种方式工作。检查[plunkr]:http://plnkr.co/edit/EcXidf6oZ5pBQC4FPV7Z?p=preview
关于解析函数 $modal.open 函数中的resolve 意味着当resolve Promise 成功时,它将打开模态弹出窗口。 这是 [Angular Bootstrap 库] 的一部分:http://angular-ui.github.io/bootstrap/ $modal 是一项快速创建 AngularJS 支持的模态窗口的服务。 我从文档[链接]复制了以下内容:http://angular-ui.github.io/bootstrap/#/modal
resolve - members that will be resolved and passed to the controller as locals; it is equivalent of the resolve property for AngularJS routes
虽然它相当于 AngularJS 路由的解析属性,但它的意思是在模态弹出窗口的上下文中。
使代码正常工作...
对于从模态 Controller (modalController)到cntr的通信,我使用了广播和事件。 在模式提交时,我将引发广播事件并使用以下代码订阅它。
广播事件。
$rootScope.$broadcast('modalSubmit', {
modalText: $scope.modaldata.passedValue // send whatever you want
});
订阅事件。
$scope.$on('modalSubmit', function(event, data) {
console.log(data); // 'Data to send'
$scope.textValue = data.modalText;
});
还有一个问题。请注意 modalController 中的以下代码。我以前也遇到过这个奇怪的问题。 我替换了
$scope.passedValue = textValue;
具有以下内容
$scope.modaldata = {
passedValue: textValue
};
关于javascript - 解析有什么用以及如何从弹出屏幕发送数据以在 Angular JS 中查看?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25749114/