1

I am trying to learn AngularJS and am having some trouble with my first app. I want to use ng-view to assign html files to different links, but nothing happens when I click the link. I must be missing something.

index.html

<!doctype html>
<html lang="en" ng-app="customerApp" ng-controller="customerControllers" >
<head>
<title>Customer Demo App</title>
  <script src="lib/angular/angular.js"></script>
  <script src="lib/angular/angular-route.js"></script>
  <script src="js/app.js"></script>
    <script src="js/controllers.js"></script>               
</head>
<body>

<ul class="nav">
        <li><a href="#/CustomerList"> List Customers </a></li>
        <li><a href="#/CustomerForm"> Add/Edit Customer </a></li>
</ul>

<div ng-view></div>

</body>

</html>

js/app.js

/* App Module */

var customerApp = angular.module('customerApp', ['ngroute', 'customerControllers' ]);

customerApp.config([$routeProvider,
        function ($routeProvider) {
            $routePRovider.
            when('/CustomerForm',{
                templateUrl: 'partials/customer-form.html',
                controller: 'customerCtrl'
            }).
            when('/CustomerList',{
                templateUrl: 'partials/customer-list.html',
                controller: 'customerLstCtrl'
            }).
            otherwise({
                redirectTo: '/CustomerForm'             
            });
        }]);

js/controller.js

customerApp.controller('customerCtrl', ['$scope', function($scope) {

    $scope.heading = 'Add / Edit Customer';

});


customerApp.controller('customerLstCtrl', ['$scope', function($scope) {

    $scope.heading = 'Customer List';

});

partials/customer-form.html

<h1>{{heading}}</h1>

<div>
    <form>
        <label>Name</label>
        <input type="text" ng-model="customer.name" /></br>
        <lablel>Email</lablel>
        <input type="text" ng-model="customer.email"/></br>
        <label>Telephone</label>
        <input type="text" ng-model="customer.phone"/></br>
        <label>Address</label>
        <label>Street</label>
        <input type="text" ng-model="customer.street" /></br>
        <label>City</label>
        <input type="text" ng-model="customer.city"/></br>
        <label>State</label>
        <input type="text" ng-model="customer.state"/></br>
        <label>Zip</label>
        <input type="text" ng-model="customer.zip"/></br>
    </form>

    </p>{{customer}}</p>
</div>

partials/customer-list.html

<h1>{{heading}}</h1>
2
  • var customerApp = angular.module('customerApp', ['ngRoute', 'customerControllers' ]); Commented Mar 24, 2014 at 20:20
  • Without knowing if you have any script errors or other problems, I can tell you having ng-controller="customerControllers" in your html tag makes no sense and may be breaking the entire application. And since you aren't namespacing your controllers you don't need to include it in your module declaration either (angular.module('customerApp', ['ngroute']);) Commented Mar 24, 2014 at 20:30

1 Answer 1

2

as the guys mentioned, there was a couple of syntax, naming errors, in any case here is your app fixed with no bugs.

Live example: http://plnkr.co/edit/RDL00s51y37VbNJICqr5?p=preview

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

1 Comment

Cool, Thank you. Appreciate the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.