angularjs路由visualstudio

时间:2015-11-08 16:13:34

标签: asp.net angularjs visual-studio-2015 visual-studio-debugging

我正在使用Visual Studio Community 2015学习angularjs。一切正常,直到我开始路由。我不知道如何使用服务器端要求来测试我的代码和路由以及URL中的#。

当我调试时,我得到链接但没有添加ngview的HTML片段。我怀疑我必须做一些事情让服务器识别URL中的#,但经过几天的阅读/搜索,没有运气(我已经读过有关更改web.config或添加一些C#代码,但这些都不适合我)。

我的问题:

  • 鉴于下面的代码,我是否有Angularjs问题?
  • 如何使社区2015上的服务器识别URL中的#,我该怎么做?
  • 调试此方法的最佳方法是什么?现在,我只是得到一个空白页面,没有错误消息,没有任何链接工作; ng-view没有按预期显示html片段。

在社区2015中,我使用Visual C#>> Web>> asp.net app>>空模板启动了新项目。

这是我的路线代码: index.html中 ngview

<div class="main-wrapper">
<div ng-view></div>       

加载ngRoute库

    <!-- AngularJS -->
    <!--<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>-->
    <script src="Scripts/angular.min.js"></script>
    <script src="Scripts/angular-route.min.js"></script>
    <script src="Scripts/angular-sanitize.min.js"></script>

    <script src="js/app.js"></script>
    <script src="js/routes.js"></script>

    <!-- Controllers -->
    <script src="js/controllers/instructionsController.js"></script>
    <script src="js/controllers/faqController.js"></script>

在app.js中导入ngRoute模块

    (function () {
        'use strict';
         angular.module('VideoOnTheMove', ['ngRoute', 'ngSanitize'])       
    })();

Route.js

    angular.module('VideoOnTheMove')
.config(['$routeProvider', function ($routeProvider) {

    $routeProvider.when('/home', {
        templateUrl: '/templates/pages/home/index.html'
    })

    .when('/overview', {
        templateUrl: '/templates/pages/overview/index.html'
    })

    .when('/instructions', {
        templateUrl: '/templates/pages/instructions/index.html',
        controller: 'instructionController',
        controllerAs: 'instructionsCtrl'
    })

    .when('/faq', {
        templateUrl: '/templates/pages/faq/index.html',
        controller: 'instructionsController',
        controllerAs: 'faqCtrl'
    })

    .when('/checklist', {
        templateUrl: '/templates/pages/checklist/index.html'
    })

    .when('/', {
        redirectTo: 'home'
    })

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

}]);

1 个答案:

答案 0 :(得分:1)

您的控制器脚本应出现在路由配置脚本

之前
<script src="Scripts/angular.min.js"></script>
<script src="Scripts/angular-route.min.js"></script>
<script src="Scripts/angular-sanitize.min.js"></script>

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

<!-- Controllers -->
<script src="js/controllers/instructionsController.js"></script>
<script src="js/controllers/faqController.js"></script>

<script src="js/routes.js"></script>
相关问题