J
J
JackDrakkar2015-11-12 01:01:49
Angular
JackDrakkar, 2015-11-12 01:01:49

Why doesn't ng-view render the html template?

Not to say that for a long time, but probably for a month and a half I have been interested in angular.js. It seems like some kind of understanding appeared, so I decided that it would not be bad to try to write something to consolidate.
Faced a very banal thing. And I don't know how to get out of it.
There is a node.js server that returns:

app.get('/', function(req, res){
    res.sendfile(path.join(staticPath, 'index.html'));
});

By the way, I started learning node.js in conjunction with angular.js.
The page is successfully retrieved via http://localhost:(port)
<!DOCTYPE html>
<html>
  <head>
    <title>App</title>
  </head>

  <body ng-app="app">

  <div>
      <div ng-view></div>
    </div>
    
    <script type="text/javascript" src="lib/angular.js"></script>
    <script type="text/javascript" src="lib/angular-route.js"></script>
    <script type="text/javascript" src="lib/angular-websocket.js"></script>
    <script type="text/javascript" src="lib/snap.svg-min.js"></script>
    <link rel="stylesheet" type="text/css" href="lib/stylesheet.css">
    <script type="text/javascript" src="index.js"></script>
    <script type="text/javascript" src="menu/index.js"></script>

  </body>
</html>

angular-route.js seems to be connected (this point has come up more than once when searching for an answer to my question)
The application itself:
angular.module('app',[
    'ngRoute',
    'ngWebSocket'
])
.config(function ($routeProvider, $locationProvider){
        $routeProvider.when('/',{
            templateUrl: 'menu/menu.html',
            controller: 'MenuController'
        });
        $routeProvider.otherwise({
            redirectTo: '/'
        });
        $locationProvider.html5Mode(true);
});

I will not give the controller code, because there, in general, everything is commented out so far and only 1 single working line:
console.log('Menu Controller');
And everything would be fine, but ng-view remains empty, and there is no "Menu Controller" line in the console.
In the menu.html template, the following code:
<div>
    <div>
        <p>Some text string</p>
    </div>
</div>

There are no errors in the console either, which is even more upsetting, because. I don't even know where to turn anymore. At the same time, I understand that due to lack of experience, the error will most likely turn out to be terribly commonplace, but maybe someone knows how to solve this problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question