{"id":2163,"date":"2022-08-30T15:22:34","date_gmt":"2022-08-30T15:22:34","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/04\/angular-js-redirect-crashing-browser-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:22:34","modified_gmt":"2022-08-30T15:22:34","slug":"angular-js-redirect-crashing-browser-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/angular-js-redirect-crashing-browser-collection-of-common-programming-errors\/","title":{"rendered":"angular.js redirect crashing browser-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to do a simple TODO sample with angular.js (using routes). I could open the form to create a New Task, but when I click on &#8220;Back&#8221; button (after create a new one), it always crashes my browser.<\/p>\n<p>I&#8217;ve tried config the &#8216;\/&#8217; route and use .otherwise too, but I&#8217;m still getting the same result.<\/p>\n<p>What I&#8217;m doing wrong?<\/p>\n<pre><code>\/\/listTasks.htm\n\n    \n    \n        \n            TODO List\n        \n        \n            \n                New Task\n                <\/code><\/pre>\n<ul id=\"listTasks\">\n<li data-ng-repeat=\"task in tasks\"><code>{{ task.name }}<\/code><\/li>\n<\/ul>\n<pre>\n            \n            \n                \n            \n            \n                 \n            \n                var app = angular.module(\"appTodoList\",['ngRoute']);\n\n                app.config(function ($routeProvider) \n                {\n                    $routeProvider\n                        .when('\/list',\n                        {\n                            controller:'TodoCtrl',\n                            templateUrl: 'listTasks.htm'\n                        })\n                        .when('\/new',\n                        {\n                            controller:'TodoCtrl',\n                            templateUrl: 'newTask.htm'\n                        });\n                });\n\n                app.controller('TodoCtrl', function($scope) \n                {           \n                    $scope.tasks = [];          \n                    $scope.addTask = function ()\n                    {   \n                        $scope.tasks.push({name: $scope.new.TaskName});\n                    };\n                });\n\n\n            \n        \n    \n<\/pre>\n<p><code>\/\/newTask.htm<\/code><\/p>\n<pre><code><code>\n    \n    \n\nBack\n<\/code><\/code><\/pre>\n<p>PS: I&#8217;m using Firefox 26<\/p>\n<ol>\n<li>\n<p>Firefox crashes because there is an infinite loop in your code. When you nagivate to <code>\/listTasks<\/code> it will load <code>\/listTasks<\/code> again in the <code>ng-view<\/code> and so on.<\/p>\n<p>Instead of <code>listTasks.htm<\/code> containing the route, place the route in another page like <code>index.htm<\/code><\/p>\n<pre><code>  $routeProvider.when('\/list',\n            {\n                controller:'TodoCtrl',\n                templateUrl: 'listTasks.htm'\n            })\n            .when('\/new',\n            {\n                controller:'TodoCtrl',\n                templateUrl: 'newTask.htm'\n            })\n            .when('\/',\n            {\n                redirectTo: '\/list'\n            });\n<\/code><\/pre>\n<p>By the way, the tasks aren&#8217;t being saved because a new controller is created per view instance but that&#8217;s an unrelated problem<\/p>\n<p>See sample<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-01-04 02:49:16. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to do a simple TODO sample with angular.js (using routes). I could open the form to create a New Task, but when I click on &#8220;Back&#8221; button (after create a new one), it always crashes my browser. I&#8217;ve tried config the &#8216;\/&#8217; route and use .otherwise too, but I&#8217;m still getting the same [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2163","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2163"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2163\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}