6

我正在爲前端開發一個AngularJS的Web應用程序,我試圖設置路由並顯示視圖,到目前爲止甚至ng-include和其他東西都適用於我,但沒有NG-觀點 我正在開發在Visual Studio中,當我運行的應用程序它使用本地服務器(本地主機)AngularJS ng-view not showing view

,這裏是我的目錄結構

- ASP.NET project 
---- Css 
---- Scripts 
-------- App 
-------- app.js 
----------- Home 
-------------- Controllers 
------------------ index-controller.js 
---- Views 
------- Partials 
---------- navbar.html 
------- home.html 
- index.html 

這裏的MI的index.html

<!DOCTYPE html> 
 
<html xmlns="http://www.w3.org/1999/xhtml"> 
 
<head> 
 
    <title>Scolaris</title> 
 
    <!--Import materialize.css--> 
 
    <link type="text/css" rel="stylesheet" href="Content/materialize/css/materialize.css" media="screen,projection" /> 
 

 
    <!--Let browser know website is optimized for mobile--> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> 
 
</head> 
 
<body ng-app="app_module"> 
 

 
    <ng-include src="'Views/Partials/navbar.html'"/> 
 

 
    <div ng-view></div> 
 

 
    <!--Import jQuery before materialize.js--> 
 
    <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script> 
 
    <script type="text/javascript" src="Content/materialize/js/materialize.js"></script> 
 
    <script type="text/javascript" src="Scripts/angular.js"></script> 
 
    <script type="text/javascript" src="Scripts/angular-route.js"></script> 
 
    <script type="text/javascript" src="Scripts/App/app.js"></script> 
 
    <script type="text/javascript" src="Scripts/App/Home/Controllers/index-controller.js"></script> 
 
    <script type="text/javascript" src="Scripts/initialization.js"></script> 
 
</body> 
 
</html>

這裏是我的app.js

'use strict'; 
 
var app_module = angular.module('app_module', ['ngRoute']); 
 
app_module.config(['$routeProvider', function ($routeProvider) { 
 
    $routeProvider 
 
     .when('/', { 
 
      templateUrl: '/Views/home.html', 
 
      controller: 'indexController' 
 
     }) 
 
     .otherwise({ 
 
      redirectTo: '/' 
 
     }); 
 
}]); 
 
/* tried with ../../Views/home.html, ../Views/home.html, etc and nothing */

當我加載它正確地加載和網站,如果我看到了我的請求可以清楚地看到,它的請求home.html的與304狀態代碼,事情是div與ng-view不顯示home.html中的html,這可能是由於什麼?

+1

控制檯中的任何錯誤?嘗試刪除'ng-include'並檢查是否'ng-view loading'。 – Zee

+0

@ Sourabh-試圖刪除加載的ng-include和ng-view,爲什麼是這樣,我怎麼能讓它們一起工作呢? – HardCodeStuds

+0

'index.html'和'Views'文件夾在同一個目錄下嗎? –

回答

0

我已經解決了該問題,方法是將<ng-include>標記更改爲< div ng-include="srctoview">標記。如果任何人有這個問題,我會建議這樣做,或者像這樣回答using a controller

感謝@ Sourabh-爲我帶來了答案。

+0

你有沒有看過我的回答? –

0

close <ng-include>指令正確,因爲瀏覽器正在打包你的<ng-view>裏面的<ng-include>。它會解決問題。正如@ pankaj已經建議的那樣。