Skip to content

Commit be06219

Browse files
committed
两个控制器实现数据共通
1 parent 157bcc3 commit be06219

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

public/app/app.html

+1
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,6 @@
100100

101101
<script src="js/app/controllers.js"></script>
102102
<script src="js/app/login.js"></script>
103+
<script src="js/app/index.js"></script>
103104
</body>
104105
</html>

public/app/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="container " style="padding-top:70px;" ng-controller="IndexCtrl">
1+
<div class="container " style="padding-top:70px;">
22
<div class="row">
33
<div class="col-md-2">
44
<div class="list-group">

public/js/app/controllers.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ var app=angular.module('ngView', ['ngRoute']);
22

33
app.config(function($routeProvider) {
44
$routeProvider.when('/index', {
5-
templateUrl: 'app/index.html'
5+
templateUrl: 'app/index.html',
6+
controller:IndexCtrl
67
});
78
$routeProvider.when('/login', {
89
templateUrl: 'app/login.html',
@@ -20,15 +21,19 @@ app.config(function($routeProvider) {
2021
});
2122
});
2223

23-
// app.controller('ngView', function ($scope, $http) {
24-
// $scope.resetLogin=function(){
25-
// alert(1);
26-
// }
27-
// })
2824

29-
function IndexCtrl($scope, $http, $templateCache) {
25+
app.factory('User', [function() {
26+
User={
27+
set:function(info){
28+
this.info=info;
29+
},
30+
get:function(){
31+
return this.info;
32+
}
33+
}
34+
return User;
35+
}]);
3036

31-
}
3237

3338

3439

public/js/app/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function IndexCtrl($scope, $http, $location ,User) {
2+
var userInfo=User.get();
3+
var stockCode=userInfo.stock.join(",");
4+
$scope.url = 'http://xueqiu.com/stock/quote.json?code='+stockCode+'&'+xueqiuUrl+'&callback=JSON_CALLBACK';
5+
$http({method: 'JSONP', url: $scope.url}).success(function(data, status) {
6+
//alert(1);
7+
// data=stock.index.ajaxStockTime(data);
8+
// // $scope.stocks=watchList=data.quotes;
9+
// $scope.stocks=data.quotes;
10+
});
11+
}

public/js/app/login.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function loginCtrl($scope, $http, $location){
1+
function loginCtrl($scope, $http, $location, User){
22
$scope.formShow=true;
33
$scope.errorShow=false;
44
$scope.toggle=function(){
@@ -8,15 +8,15 @@ function loginCtrl($scope, $http, $location){
88
if(this.name&&this.password){
99
$http.post("/loginAjax", {name:this.name,password:this.password}).success(function(data,status){
1010
if(data.ok){
11-
// $scope.$parent.resetLogin();
1211
//http://blog.jobbole.com/54817/
12+
//数据传到外部
13+
User.set(data.info)
1314
$location.path("/index");
1415
}else{
1516
$scope.errorShow=true;
16-
$scope.error=data.message
17+
$scope.error=data.message;
1718
}
1819
});
1920
}
20-
2121
}
22-
}
22+
}

0 commit comments

Comments
 (0)