Yoa*_*rtz 9 angularjs ionic-framework
我有一些奇怪的问题,我似乎无法找到解释.我显示一个带有单个输入的弹出窗口,我绑定到我的范围内的变量我将$ scope传递给弹出窗口.绑定工作,我可以看到设置的变量,它随着我的输入而改变.但是一旦我关闭弹出窗口并在"点击"功能上注销该范围变量"它似乎又恢复到原始值.
编辑:一支笔,展示了一般问题:http: //codepen.io/anon/pen/ariDh
码:
var sendPopup = $ionicPopup.show({
title: $translate.instant(popupTitle),
subTitle: $translate.instant('POPUP_WITH_MESSAGE_SUBTITLE'),
templateUrl: 'templates/leave-message-popup.html',
scope: $scope,
buttons: [
{ text: $translate.instant('BUTTON_CANCEL') },
{
text: $translate.instant('BUTTON_SEND'),
type: 'button-positive',
onTap: function(e) {
console.log("contact message:" + $scope.contactMessage);
if (!$scope.contactMessage) {
console.log("preventing default");
e.preventDefault();
} else {
$scope.sendData(contactType);
}
}
},
]
});
Run Code Online (Sandbox Code Playgroud)
模板:
<input type="text" ng-model="contactMessage" name="message" placeholder="{{'PLACEHOLDER_CONTACT_MESSAGE' | translate}}" required autofocus>
{{contactMessage}}
Run Code Online (Sandbox Code Playgroud)
您的codepen的这个修改版本显示了这个工作:http://codepen.io/anon/pen/rgBLa
将变量更改为正确传递给弹出窗口的作用域上的对象允许在变化时将其绑定回控制器作用域.由于传递给$ ionicPopup时范围的管理方式,因此需要这样做.
$scope.contactMessage = { text: "text" }
Run Code Online (Sandbox Code Playgroud)
然后更新标记以正确查看范围上的此属性.
<input type="text" ng-model="contactMessage.text" name="message">
{{contactMessage.text}}
Run Code Online (Sandbox Code Playgroud)
我希望这对您的问题有所帮助.
| 归档时间: |
|
| 查看次数: |
18214 次 |
| 最近记录: |