Javascript 使用ngroute传递参数

Javascript 使用ngroute传递参数,javascript,angularjs,Javascript,Angularjs,这是我的 angularroute.html <html xmlns="http://www.w3.org/1999/xhtml" ng-app="AngularApp"> <head> <title></title> <script src="angular.js"></script> <script src="angular-route.js"></script>

这是我的

angularroute.html

<html xmlns="http://www.w3.org/1999/xhtml" ng-app="AngularApp">
<head>
    <title></title>
    <script src="angular.js"></script>
    <script src="angular-route.js"></script>
    <script type="text/javascript">

        var AngApp = angular.module('AngularApp', ['ngRoute']);
        AngApp.config(function ($routeProvider) {
            $routeProvider
                .when('/Route1/:ID', {
                    templateUrl:'Route1.html',
                    controller:'Route1'

                })
                .when('/Route2', {
                    templateUrl: 'Route2.html',
                    controller:'Route2'
                })

                .otherwise({
                    redirectTo: '/'
                });
        });

    </script>

            </head>
            <body>

                <p>Routing Explained</p>
                <a href="#Route1/100">Route1</a><br>
                <a href="#Route2">Route2</a>
                <div ng-view>

                </div>

                <script src="Route.js"></script>       


            </body>
            </html>
Route1.html

<html xmlns="http://www.w3.org/1999/xhtml" ng-app="Route1">
<head>
    <title></title>

</head>
<body ng-controller="Route1">


    {{ID}}

    {{4+10}}

</body>
</html>

{{ID}
{{4+10}}
问题是它加载了页面,但我无法接收参数值,在route1.html上,表达式也没有得到计算。 有什么问题吗?
谢谢。

从路线模板中删除所有不需要的内容。只需要在模板正文中添加的内容

这将包含在您在路线中配置的控制器的角度视图中。这是一个部分的,而不是一个完整的html文件

您的
route.js
代码也不正确。您可以创建一个模块
angular.module('route',[]).controller('route1Controller',function(){…})
并将其用作应用程序中的依赖项

没有了括号,就像你在
route.js
中那样,你得到了一个已经定义好的模块

请在下面或本文档中查看您的更新代码

var AngApp=angular.module('AngularApp',['ngRoute']))
.controller('Route1Controller',Route1Controller)
.控制器(“路由控制器”,路由控制器);
AngApp.config(函数($routeProvider){
$routeProvider
.when('/Route1/:ID'{
templateUrl:'Route1.html',
控制器:'Route1控制器'
})
。当(“/Route2”{
templateUrl:'Route2.html',
控制器:'Route2控制器'
})
.否则({
重定向到:'/'
});
});
功能路由1控制器($scope,$routeParams){
$scope.ID=$routeParams.ID;
}
功能路由控制器($scope){
}

路线1
{{ID}
{{4+10}}
路线2
{{4+10}}
路由解释



可能尝试在HTML页面中包含angular.js。
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="Route1">
<head>
    <title></title>

</head>
<body ng-controller="Route1">


    {{ID}}

    {{4+10}}

</body>
</html>