2

I am trying to create a simple Angular app and I have recently added a router in route.js. For some reason the association isn't being made between mainCtrl and someview.html The reason I know this is because the view isn't being injected in <div ng-view></div> Anyone have any idea why?

My folder structure is the following

root
------/app
----------routes.js
----------/views
-----------------someview.html
------/public
---------mainCtrl.js
---------index.html
server.js

mainCtrl.js

angular.module('LiveAPP',[])

.controller('MainCtrl', function($scope) {
    $scope.Artists = [
      {name:"Blink 182",age:14},
      {name:"Led Zeppelin",age:12},
      {name:"Lil Wayne",age:11}
    ];
    $scope.number = 100;
});

someview.html

<div>{{number}}</div>

route.js

angular.module('LiveAPP', ['ngRoute'])

.config(function($routeProvider, $httpProvider) {
$routeProvider
  .when('/', {
    templateUrl : '/views/someview.html',
    controller  : 'MainCtrl'
  })

});

index.html

<!doctype html>
<html ng-app='LiveAPP'> 
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js">
    </script>
    <link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28//angular-route.min.js"></script>
    <script src="mainCtrl.js"></script> 
  </head>
  <body>
    <div ng-view></div>
  </body>
</html>

server.js

var express = require('express');
var app = express();

app.use(express.static(__dirname + '/public'));

app.listen(3000);

console.log("Listening at 3000")
0

1 Answer 1

1
angular.module('LiveAPP',[])
    .controller('MainCtrl', function($scope) {

Here, you define a module LiveAPP, that doesn't depend on any other module, and add a controller to this module.

angular.module('LiveAPP', ['ngRoute'])
    .config(function($routeProvider, $httpProvider) {

And here, you redefine, once again, a module with the same name, depending on ngRoute. But since you're redefining it, you effectively overwrite the previously defined module and all its components.

A module must be defined once, and only once.

I don't know much about express, but I also don't understand why all your files are not under public, since that is apparently the directory that the web server serves.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.