如何在jsp中使用ng-view?

时间:2016-12-10 08:11:19

标签: angularjs jsp ng-view

我的条件:

File structure

  1. MainController正确提供Index.jsp。
  2. Index.jsp正确连接到main.js。
  3. main.js不会注入" inner / home.html"进入ng-view。
  4. 为什么" inner / home.html"没注射?

    控制器:

    package com.treeweb.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    
    /**
     * Created by bluecastle on 8-12-16.
     */
    @Controller
    @RequestMapping("/")
    
    public class MainController {
    
        @RequestMapping(method = RequestMethod.GET)
        public String getIndexPage() {
            return "Index";
        }
    }
    

    的index.jsp:

    
    
    <%--
      Created by IntelliJ IDEA.
      User: bluecastle
      Date: 8-12-16
      Time: 8:49
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <html ng-app="treeApp">
    <head>
        <title>Treeweb</title>
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" />
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.css"/>
        <link href="<c:url value='/static/css/app.css' />" rel="stylesheet"></link>
    </head>
    <body>
    <header>
        <nav class="navbar navbar-default">
            <div class="container">
                <div class="navbar-header">
                    <a class="navbar-brand" href="/">Angularjs</a>
                </div>
    
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="#"><i class="fa fa-home"></i> Home</a></li>
                    <li><a href="#about"><i class="fa fa-shield"></i> About</a></li>
                    <li><a href="#contact"><i class="fa fa-comment"></i> Contact</a></li>
                </ul>
            </div>
        </nav>
    </header>
    <div id="main">
        <div ng-view></div>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular-route.js"></script>
    <script src="<c:url value='/static/js/main.js' />"></script>
    </body>
    </html>
    &#13;
    &#13;
    &#13;

    main.js:

    &#13;
    &#13;
    var treeApp = angular.module('treeApp', ['ngRoute']);
    
    treeApp.controller('homeController', function($scope) {
        // implementations to be made
    });
    
    treeApp.config(function($routeProvider) {
        $routeProvider
            .when('/', {
                templateUrl : 'inner/home.html',
                controller  : 'homeController'
            });
    });
    &#13;
    &#13;
    &#13;

0 个答案:

没有答案