angularJS--多个控制器之间的数据共享
2015-08-04 09:59
633 查看
为了在控制器之间共享数据,需要在服务中添加一个用来储存用户名的方法。记住,服务在
应用的生命周期内是单例模式的,因此可以将用户名安全地储存在其中。
应用的生命周期内是单例模式的,因此可以将用户名安全地储存在其中。
<!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>
相关文章推荐
- AngularJS Tutorial(18)from w3school
- AngularJS Tutorial(17)from w3school
- AngularJS Tutorial(16)from w3school
- AngularJS Tutorial(15)from w3school
- AngularJS Tutorial(14)from w3school
- AngularJS Tutorial(13)from w3school
- AngularJS Tutorial(12)from w3school
- AngularJS Tutorial(11)from w3school
- AngularJS Tutorial(10)from w3school
- AngularJS Tutorial(9)from w3school
- AngularJS Tutorial(8)from w3school
- AngularJS Tutorial(7)from w3school
- AngularJS Tutorial(6)from w3school
- AngularJS Tutorial(5)from w3school
- AngularJS Tutorial(4)from w3school
- AngularJS Tutorial(3)from w3school
- AngularJS Tutorial(2)from w3school
- AngularJS Tutorial(1)from w3school
- angularjs入门案例 新玩具-中午吃神马
- angular之Directive - Compile vs. Link