日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

angularJS--多个控制器之间的数据共享

發布時間:2025/4/16 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 angularJS--多个控制器之间的数据共享 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

為了在控制器之間共享數據,需要在服務中添加一個用來儲存用戶名的方法。記住,服務在
應用的生命周期內是單例模式的,因此可以將用戶名安全地儲存在其中。

<!DOCTYPE html> <html> <head><meta charset="utf-8"><title>12-angularjs的多個控制器數據共享</title><script src="../js/angularjs.js"></script><script src="../js/index12.js"></script></head> <body> <!-- angularjs的數據綁定,雙向綁定,M,V,c之間的綁定 --><div ng-app="myApp"><div ng-controller= "firstController"><input type="text" ng-model="person.name" value="" />firstData--{{person.name}}</div><div ng-controller="secondController"><input type="text" value="" />secondData--{{person.name}}<div ng-controller= "firstController"><input type="text" ng-model="Data.message" value="" />firstData--{{Data.message}}</div><div ng-controller="secondController"><input type="text" value="" />secondData--{{Data.message}}</div></div></div></body> </html>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 var?myApp = angular.module('myApp', []); myApp.factory('Data',?function(){ ????return?{message:'小平果'}; }); myApp.controller('firstController',??function($scope,Data){ ????$scope.person = { ????????name:?"肖果平" ????}; ????$scope.Data = Data; }); myApp.controller('secondController',??function($scope,Data){ ????$scope.person = $scope.$$prevSibling.person;//基本類型不能變的,只有對象才能引用 ????$scope.Data = Data; });

  

版權聲明:本文為小平果原創文章,轉載請注明:http://blog.csdn.net/i10630226

轉載于:https://www.cnblogs.com/dingxiaoyue/p/4948260.html

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的angularJS--多个控制器之间的数据共享的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。