ng-View does not render content - Angularjs

Asked

Viewed 591 times

3

When I access my index.php, I ask in my Angular route settings that it calls the "index.php" view inside the "view" folder, but it finds but does not render anything on my screen

var app = angular.module('app',['ngRoute']);

app.config(function($routeProvider,$locationProvider){
	$routeProvider
		.when('/',{
			templateUrl: 'view/index.php',
			controller:'search'
			
		}).otherwise({redirectTo:"/"})

    //Se descomentar tbm não funciona
	//$locationProvider.html5Mode(true);
})
<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<link rel="stylesheet" href="/assets/css/bootstrap.min.css">
	<link rel="stylesheet" href="/assets/css/font-awesome.min.css">
</head>
<body>
	
	<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
		<div class="container">
			<a class="navbar-brand" href="#">Teste</a>

			<ul class="nav navbar-nav">
				<li><a href="">Home</a></li>
				<li><a href=""></a></li>
				<li><a href=""></a></li>
				<li><a href=""></a></li>
				<li><a href=""></a></li>
			</ul>
		</div>
	</nav>

	<div ng-view>
		
	</div>

	<script src="/assets/js/jquery.js"></script>
	<script src="/assets/js/bootstrap.min.js"></script>

	<script src="/angularapp/setup/angular.min.js"></script>
	<script src="/angularapp/setup/angular.min.js.map"></script>
	<script src="/angularapp/setup/angular-route.min.js"></script>
	<script src="/angularapp/setup/angular-route.min.js.map"></script>
	
	<script src="/angularapp/config.js"></script>
	<script src="/angularapp/controllers/search.js"></script>
</body>
</html>

1 answer

-1

so! almost sure it’s the missing controller call: you set there.

<div ng-controller="search" ng-view>
ou
<div ng-controller="search">
   <div ng-view>
</div>
  • This is not necessary. The controller will be instantiated when the view renders the page.

  • Hello Luiz, thanks for your attention, but warn me it was silly, I had reversed the name of a controller in the configs, I fixed it! Vlw

Browser other questions tagged

You are not signed in. Login or sign up in order to post.