<!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" : "演员" }]
时间: 2024-10-07 02:49:26