码迷,mamicode.com
首页 > 其他好文 > 详细

Angular 学习笔记——ng-Resource1

时间:2015-12-16 01:41:49      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE HTML>
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script src="http://cdn.bootcss.com/angular.js/1.3.8/angular.min.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.8/angular-route.min.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.8/angular-resource.min.js"></script>
<script>

var m1 = angular.module(‘myApp‘,[‘ngRoute‘,‘ngResource‘]);

m1.config([‘$routeProvider‘,function($routeProvider){
    
    $routeProvider
                .when(‘/aaa/:name‘,{
                    template : ‘<div>{{data[0].name}}</div><div>{{data[0].age}}</div><div>{{data[0].job}}</div>‘,
                    controller : ‘Aaa‘
                })
                .otherwise({
                        redirectTo : ‘/aaa/zhangsan‘
                });
    
}]);

m1.controller(‘Aaa‘,[‘$scope‘,‘$resource‘,‘$location‘,‘$routeParams‘,function($scope,$resource,$location,$routeParams){
    
    $scope.$location = $location;
    
    console.log($routeParams);
    
    if($routeParams.name){
    
        var objRe = $resource( $routeParams.name +‘.json‘,{},{});
    
        $scope.data = objRe.query();
    
    }
    
}]);


</script>
</head>

<body>
<div ng-controller="Aaa">
    <input type="button" value="张三" ng-click="$location.path(‘aaa/zhangsan‘)">
    <input type="button" value="李四" ng-click="$location.path(‘aaa/lisi‘)">
    <div ng-view>
    </div>
</div>
</body>
</html>
[{
    "name" : "张三",
    "age" : "20",
    "job" : "演员"
}]

 

Angular 学习笔记——ng-Resource1

标签:

原文地址:http://www.cnblogs.com/mayufo/p/5049975.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!