Problems with Angular ngRoute links

Asked

Viewed 447 times

2

I’m trying to link. I’m working with Angularjs and did the route setup part. I have a views folder with html files.

Follows the codes:

<html ng-app="fluxo">
<head>
<title>Fluxojoin</title>
<meta charset="utf8">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
<script type="text/javascript" src="js/angular-route.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/fj.css">

<script>
angular.module("fluxo", ["ngRoute"]);
angular.module("fluxo").controller("fluxoCtrl", function ($scope, $http) {

angular.module("fluxo").config(function ($routeProvider) {
    $routeProvider.when("/entradas", {
        templateUrl: "views/entradas.html"
    });
});

});
</script>

</head>
<body ng-controller="fluxoCtrl">
<div ng-include="'views/links.html'"></div>
<div ng-view></div>
</body>
</html>

File entries.html

<link rel="stylesheet" type="text/css" href="css/fj.css">

<div class="jumbotron" align="center">
<form name="contaEntradasForm">
    <input class="form-control" type="text" ng-model="" placeholder="Nome">
    <input class="form-control" type="text" ng-model="" placeholder="Email">
    <input class="form-control" type="text" ng-model="" placeholder="Senha">
</form>
</div>

1 answer

3


Try to get the Router configuration out of the control. If the idea was to pass the controller to the page you are rendering, then do it this way below, passing the controller in the config itself:

angular.module("fluxo", ["ngRoute"]);

angular.module("fluxo").config(function ($routeProvider) {
    $routeProvider.when("/entradas", {
        templateUrl: "views/entradas.html",
        controller: 'fluxoCtrl'
    });
});
  
angular.module("fluxo").controller("fluxoCtrl", function ($scope, $http) {

});

  • That’s right @Eduardomartins! It worked. I have to put the route part before and outside the controller part. Thanks.

Browser other questions tagged

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