![](/img/trans.png)
[英]I have two divs with the same ng-controller in AngularJS, how can I make them share information?
[英]How can i share variables between views, with the same controller in AngularJS?
我有這個控制器...
app.controller('UploadController', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $timeout) {
$scope.$watch('files', function () {
$scope.upload($scope.files);
});
$scope.upload = function (files) {
if (files && files.length) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
}
}
};
}]);
我正在將從files[i]
獲得的溫度分配給var file
,因此我可以像預覽一樣在我的視圖上顯示該溫度。
<section ng-controller="UploadController">
<img ngf-src="files[0]" ng-show="files[0].type.indexOf('image') > -1">
</section>
但是我真正需要的是在模態視圖中顯示溫度。
<section ng-controller="UploadController">
<img ngf-src="files[0]" ng-show="files[0].type.indexOf('image') > -1">
</section>
模態視圖具有相同的控制器和相同的“ img”屬性,但是當我顯示模態視圖時,控制器RESTART ,這是問題的重點,我需要學習如何將變量的值保持在相同的位置。控制器,但視圖不同,無需重做操作。
基本上我需要:顯示視圖時,我的控制器不會重新啟動 。
<img src="">
采用圖片的網址或圖片的路徑。 將映像上傳到服務器后。 如果可以返回圖像URL而不是圖像數據,則應正確顯示圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.