AngularJS ng-view not displaying view

I am developing a web application with AngularJS for the front end, and I am trying to configure routing and showing views, while even ng-include and other things work for me, but not ng-view. I develop in the visual studio, and when I launch the application using local server (localhost)

here is my directory structure

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

Here is 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> 

Here is my 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 */ 

When I load the site, it loads correctly, and if I see the requests, I can clearly see that it is requesting home.html with a status code of 304, the thing is a div with ng-view that does not show html inside the house. html, what could it be because of?

+6
source share
2 answers

I solved the problem by changing the <ng-include> tag with the < div ng-include="srctoview"> . If anyone has this problem, I would recommend doing it or doing it like in this answer using a controller

Thanks @ Sourabh- for taking me away.

0
source

close <ng-include> correctly, as the browser wraps ur <ng-view> inside <ng-include> . this will solve the problem. as @pankaj already said.

0
source

Source: https://habr.com/ru/post/985928/


All Articles