Question

I've been trying to follow Dan Wahlin's YT video and implement it in a parallel way using my own data. The backend is in express and mongo, and the code below worked up until the point that I started adding routes. The two files linked to exist, and everything is running on a server, which rules out the issues of similar posters, but the partials are not loading (I see some signs that the ng-view stub has been changed by angular, but without injecting the new content). Any clues?

<html ng-app="restosApp">
<head>
</head>
<body>
<div>

    <div data-ng-view></div>

</div>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.2/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.2/angular-route.min.js"></script>

<script>
var app = angular.module('restosApp', ['ngRoute']);

app.controller('listController', function($scope, restosFactory) {

    function init() {
        restosFactory.getQnames().success(function(data){
            $scope.qnames = data;
        });         
    }

    init();
});

app.controller('editorController', function($scope, restosFactory) {

    function init() {
        restosFactory.getFullData('marius').success(function(data){
            $scope.resto = data;
        }); 
    }

    init();
});

app.config(function ($routeProvider) {
    $routeProvider
        .when('/', {
            controller: 'listController',
            templateURL: 'qname.html'
        })
        .when('/edit', {
            controller: 'editorController',
            templateURL: 'editor.html'
        })
        .otherwise({
            redirectTo: '/'
        });
});

app.factory('restosFactory', function($http){
    var factory = {};
    factory.getQnames = function() {
        return $http.get('http://localhost:3000/data');
    };
    factory.getFullData = function(q) {
        return $http.get('http://localhost:3000/edit?qname='+q);
    };
    return factory;
});
</script></body>

On the express side I have

app.get '/qname.html', (req, res) ->
    res.sendfile 'qname.html'

app.get '/editor.html', (req, res) ->
    res.sendfile 'editor.html'

and http://localhost:3000/qname.html returns the content (below) of the file seemingly correctly

<section class="container">
    <label>search qName:</label>
    <input type="text" ng-model="searchname" placeholder="Enter a name here">

    <div ng-repeat="qname in qnames | filter: searchname | orderBy: 'date':true"> <!-- Newest first -->         
        <a href="/edit?qname={{qname.qname}}">{{qname.rname}}</a>           
    </div>
</section>
Was it helpful?

Solution

Check the spelling of templateURL: it should be spelled with a lower-case r and l, i.e., templateUrl. See: the $routeProvider documentation

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top