我正在尝试修改一个 ionic 1 项目,我需要在打开时动态更改模板上的文本。
在 controller.js 我有:
//Settings
$scope.settingsData = {};
$ionicModal.fromTemplateUrl('templates/settings.html', {
scope: $scope
}).then(function(modal) {
$scope.modal2 = modal;
});
$scope.closeSettings = function() {
$scope.modal2.hide();
};
$scope.settings = function() {
$scope.modal2.show();
};
$scope.doSettings = function() {
console.log('Doing Settings', $scope.settingsData);
$timeout(function() {
$scope.closeSettings();
}, 1000);
};
模板如下所示:
<ion-modal-view>
<ion-header-bar>
<h1 class="title">App Settings</h1>
<div class="buttons">
<button class="button button-clear" ng-click="closeSettings()">Close</button>
</div>
</ion-header-bar>
<div id="myid">Text in here needs to be replaced with something when it opens</div>
</div>
</ion-content>
</ion-modal-view>
所以如果我有一个变量:
var myvar = 'Something to replace';
然后当模板打开时,上面的 var 可能是模板中的 div myid 中的文本
如何才能做到这一点?
我会尽量回答你的问题。
在您的控制器中:
$scope.myvar = 'new text here !';
在您的 html 文件中:
<div id="myid">{{myvar}}</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句