angular-phonecat icon indicating copy to clipboard operation
angular-phonecat copied to clipboard

Step 7 is broken (no output)

Open ghurley opened this issue 13 years ago • 28 comments

If you update to step-7 (git checkout -f step-7) and load the index page, nothing renders. There is no redirect from index.html to index.html# and there are no errors in the browser console or in the node server console. The "live demo" behaves the same way:

http://angular.github.io/angular-phonecat/step-7/app/

This is as of 2013-10-09 11:40 PDT.

All 5 e2e tests fail as well.

ghurley avatar Oct 09 '13 19:10 ghurley

Incidentally, all the steps in the tutorial from 5 on are broken. Steps 5-6 have a missing dependency on $http. Steps 7-8 don't do anything at all. Steps 9-11 have several errors in the js console and step 12 doesn't even exist on the live demo (404 at http://angular.github.io/angular-phonecat/step-12/app/)

ghurley avatar Oct 09 '13 19:10 ghurley

@ghurley - Would you mind opening Issues on the phonecat repo for these? Thanks

petebacondarwin avatar Oct 09 '13 19:10 petebacondarwin

I got step 7 working just now (after fiddling with about 30 tabs of various Angular docs open and the raw source handy):

First, add <script src="lib/angular/angular-route.js"></script> in the index.html below the angular.js script include, otherwise the ngRoute module and the $route service won't be available.

Then, remove the <script src="js/app.js"></script> include.

Finally, here's the correct controllers.js file:

var phonecatApp = angular.module('phonecatApp', ['ngRoute']).
  config(['$routeProvider', function($routeProvider) {
    $routeProvider.
      when('/phones', {
        templateUrl: 'partials/phone-list.html', controller: 'PhoneListCtrl'
      }).
      when('/phones/:phoneId', {
        templateUrl: 'partials/phone-detail.html', controller: 'PhoneDetailCtrl'
      }).
      otherwise({redirectTo: '/phones'});
  }]).
  controller('PhoneListCtrl', function($scope, $route, $http) {
    $http.get('phones/phones.json').success(function(data) {
      $scope.phones = data;
    });

    $scope.orderProp = 'age';
  }).
  controller('PhoneDetailCtrl', function($scope, $route, $routeParams) {
    $scope.phoneId = $routeParams.phoneId;
  });

[reformatted so it's readable]

So, what did not work:

  • defining the routes in app.js didn't work (I tried a few permutations)
  • ngRoute module and its $route and $routeParams services were unavailable due to the missing include

annismckenzie avatar Oct 09 '13 20:10 annismckenzie

@petebacondarwin: Isn't this the phonecat repo?

ghurley avatar Oct 09 '13 20:10 ghurley

:-) Yes, you are right. I am getting lost in an inbox full of issues and pull requests!

petebacondarwin avatar Oct 09 '13 20:10 petebacondarwin

Sorry, this was my bad.

@petebacondarwin let me take care of these PRs.

btford avatar Oct 09 '13 20:10 btford

@annismckenzie are you sure thats everything? It's still blank - no errors just not rendering the view

jeffkile avatar Oct 11 '13 02:10 jeffkile

@jeffkile I forked it to me. You can take a look at the changes I had to make here: https://github.com/annismckenzie/angular-phonecat/compare/step-7...step-7-working. Don't worry about the changes to the karma-e2e.conf.js – I had several projects running side-by-side.

Also I was mssing the exclusion for angular-scenario in the unit test configuration file:

exclude: ['app/lib/angular/angular-scenario.js'],

Thta's why I removed angular-scenario: unit tests were not running at all.

annismckenzie avatar Oct 11 '13 08:10 annismckenzie

Angular-phonecat had its AngularJS build updated to 1.2.0-rc2 and there were some routing changes – that's why step 7 broke. Here's a concise explanation: http://weblogs.asp.net/dwahlin/archive/2013/08/14/angularjs-routing-changes.aspx for anyone who's interested.

annismckenzie avatar Oct 12 '13 14:10 annismckenzie

If one prefer to split the app configuration to the app.js and the controllers to the controllers.js, this will work.

app.js:

var phonecatApp = angular.module('phonecatApp', [ 'ngRoute' ]);

phonecatApp.config(
        [ '$routeProvider', function($routeProvider) {
            $routeProvider.when('/phones', {
                templateUrl : 'partials/phone-list.html',
                controller : 'PhoneListCtrl'
            }).when('/phones/:phoneId', {
                templateUrl : 'partials/phone-detail.html',
                controller : 'PhoneDetailCtrl'
            }).otherwise({
                redirectTo : '/phones'
            });
        } ]);

controllers.js:

var phonecatApp = angular.module('phonecatApp');

phonecatApp.controller('PhoneListCtrl',
        function($scope, $http) {
            $http.get('phones/phones.json').success(function(data) {
                $scope.phones = data;
            });

            $scope.orderProp = 'age';
        });

phonecatApp.controller('PhoneDetailCtrl',
        function($scope, $route, $routeParams) {
            $scope.phoneId = $routeParams.phoneId;
        });

Remember to include the

  <script src="lib/angular/angular-route.js"></script>

in the index.html

kbkjeldsen avatar Oct 18 '13 07:10 kbkjeldsen

your method is not work...

this is my modify, I tried , it can work.

liucw@liucw-desktop:~/angular-phonecat$ git diff
diff --git a/app/index.html b/app/index.html
index 2808fab..cf21d04 100644
--- a/app/index.html
+++ b/app/index.html
@@ -6,6 +6,7 @@
   <link rel="stylesheet" href="css/app.css">
   <link rel="stylesheet" href="css/bootstrap.css">
   <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>
diff --git a/app/js/app.js b/app/js/app.js
index 463c913..2760e82 100644
--- a/app/js/app.js
+++ b/app/js/app.js
@@ -2,7 +2,7 @@

 /* App Module */

-var myApp = angular.module('phonecatApp', []).
+var myApp = angular.module('phonecatApp', ['ngRoute', 'phonecatApp.controllers']).
   config(['$routeProvider', function($routeProvider) {
   $routeProvider.
       when('/phones', {templateUrl: 'partials/phone-list.html',   controller: 'PhoneListCtrl'}).
diff --git a/app/js/controllers.js b/app/js/controllers.js
index 7010b4e..2170690 100644
--- a/app/js/controllers.js
+++ b/app/js/controllers.js
@@ -2,9 +2,9 @@

 /* Controllers */

-var phonecatApp = angular.module('phonecatApp', []);
+var phonecatApp = angular.module('phonecatApp.controllers', []);

-phonecatApp.controller('PhoneListCtrl', function PhoneListCtrl($scope) {
+phonecatApp.controller('PhoneListCtrl', function PhoneListCtrl($scope, $http) {
   $http.get('phones/phones.json').success(function(data) {
     $scope.phones = data;
   });

booxood avatar Oct 19 '13 03:10 booxood

This is fixed now. Please re-pull.

btford avatar Oct 22 '13 19:10 btford

Are you try? @btford

booxood avatar Oct 24 '13 09:10 booxood

I am try.

btford avatar Oct 24 '13 09:10 btford

How and where to add these dependencies in 7th step in angular phonecatapp? Kindly notify me. { "name": "angular-phonecat", "description": "A starter project for AngularJS", "version": "0.0.0", "homepage": "https://github.com/angular/angular-phonecat", "license": "MIT", "private": true, "dependencies": { "angular": "1.4.x", "angular-mocks": "1.4.x", "jquery": "~2.1.1", "bootstrap": "~3.1.1", "angular-route": "1.4.x" } }

RajeswarReddy avatar Feb 23 '16 10:02 RajeswarReddy

@RajeswarReddy - You put them in a file called bower.json in the root folder of your project.

petebacondarwin avatar Feb 23 '16 11:02 petebacondarwin

Thank u @petebacondarwin, But there are many bower.json files. 1: In angular, 2 , in Angular.animate 3)Angular.mocks which one i have to chose? If possible kindly pass me the snapshot.

RajeswarReddy avatar Feb 23 '16 12:02 RajeswarReddy

The one in the root of your project On 23 Feb 2016 12:25, "RajeswarReddy" [email protected] wrote:

There are many bower.json files. 1: In angular, 2 , in Angular.animate 3)Angular.mocks which one i have to chosse?

— Reply to this email directly or view it on GitHub https://github.com/angular/angular-phonecat/issues/69#issuecomment-187679945 .

petebacondarwin avatar Feb 23 '16 12:02 petebacondarwin

In the bower components file?

RajeswarReddy avatar Feb 23 '16 12:02 RajeswarReddy

Kindly provide me the snapshot.This task is very important for me. @petebacondarwin

RajeswarReddy avatar Feb 23 '16 12:02 RajeswarReddy