• Angular 学习笔记——ng-Resource1


    <!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" : "演员"
    }]
  • 相关阅读:
    k8s-istio记录
    k8s
    单词 -(动物)
    RxJs
    .netcore 3.1 unbuntu
    单词规整
    AutoMapper
    时间
    ye
    特殊权限
  • 原文地址:https://www.cnblogs.com/mayufo/p/5049975.html
Copyright © 2020-2023  润新知