Encountered an error in Angular1: TypeError - promise.catch does not exist as a

Upon using angular-ui-router, I encountered the following error while clicking on the links view1 and view2 in index.html. The same example worked with the regular angular router. Is there something missing in the code? Thanks.

TypeError: promise.catch is not a function
    at silenceUncaughtInPromise (angular-ui-router.js:1079)
    at silentRejection (angular-ui-router.js:1082)
    at angular-ui-router.js:1771
    at handleError (angular-ui-router.js:1614)
    at TransitionHook.invokeHook (angular-ui-router.js:1631)
    at Function.TransitionHook.invokeHooks (angular-ui-router.js:1729)
    at Transition.run (angular-ui-router.js:3475)
    at StateService.transitionTo (angular-ui-router.js:7015)
    at StateService.go (angular-ui-router.js:6911)
    at angular-ui-router.js:8862

app.js -

angular.module('app1',[
'ui.router',
'app.controller']).
config(function($stateProvider,$urlRouterProvider,$locationProvider) {
        $stateProvider.state('view1',{
            url: '/view1',
            controller: 'Controller1',
            templateUrl: '/partials/view1.html'
        }).state('view2',{
            url: '/view2/:firstname/:lastname',
            controller: 'Controller2',
            templateUrl: '/partials/view2.html',
            resolve: {
                names: function(){
                    return ['JavaScript','JQuery','Angular','Bootstrap'];
                }
            }
        });
        $urlRouterProvider.otherwise('/index');
        $locationProvider.html5Mode(true);
});

controller.js -

angular.module('app.controller',[]).
    controller('Controller1',function($scope,$location,$state){
        $scope.loadView2 = function(){      
                $state.go('view2', {
                        firstname: $scope.firstname,
                        lastname: $scope.lastname
                });
            //$location.path('/view2/'+$scope.firstname+'/'+$scope.lastname);
        }
    }).controller('Controller2',function($scope,$stateParams,names){
        $scope.firstname = $stateParams.firstname;
        $scope.lastname = $stateParams.lastname;
        $scope.names = names;
    });

index.html -

<!DOCTYPE html>
<html>
<head>
    <script src="/jquery/jquery.js"></script>
    <script src="/angular/angular.js"></script>
    <script src="/angular/angular-route-1.2.3.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.3/angular-ui-router.js"></script>
    <script src="/bootstrap/js/bootstrap.js"></script>
    <script src="/js/app.js"></script>
    <script src="/js/controllers.js"></script>
    <link rel="stylesheet" type="text/css" href="/bootstrap/css/bootstrap.css"/>
    <title>
        Angular App
    </title>
</head>
<body ng-app="app1">
    <div>
    <ul class="menu">
<li><a ui-sref="view1">view1</a></li>
<li><a ui-sref="view2">view2</a></li>
</ul>
        <ng-view></ng-view>
    </div>
</body>
</html>

Answer №1

Tip 1
The Angular UI-Router is being used.

To make the necessary changes, in your index.html, swap out <ng-view></ng-view> with <div ui-view></div>

If you were using ngRoute, then ng-view would have been appropriate. But, for your current setup with ui.router, it's best to use <div ui-view></div>

Tip 2
Given that html5Mode is being utilized, ensure you specify the base href within your index.html.
Include <base href="/"> inside the <head> section of your index.html

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Insert an HTML element or Angular component dynamically when a specific function is called in an Angular application

Currently, I am working on a component that contains a button connected to a function in the .ts file. My goal is to have this function add an HTML element or make it visible when the button is clicked. Specifically, I would like a dynamic <div> elem ...

Utilizing React in conjunction with i18next and incorporating the HTML attribute lang

My website is built using React and i18next, with support for multiple languages. I am trying to change the 'lang' attribute in my HTML page. How can I achieve this? Even though I am using the i18next-browser-languagedetector, the lang attribut ...

A customized Angular directive for encapsulating ng-messages functionality

A custom angular directive has been developed to manage the display of error messages by combining ng-messages & ng-message-exp directives. This was done in order to create a personalized popover error message feature. To make this possible, a parent cont ...

Guide to Changing the Value of a Textbox Using Form jQuery

For instance: <form id="example1"> <input type="text" name="example_input"> </form> <form id="example2"> <input type="text" name="example_input"> </form> In the code above, both text boxes have the same name. H ...

When I click on .toggle-menu, I want the data-target to have a toggled class and the other divs to expand

Looking to achieve a functionality where clicking on .toggle-menu will toggle a class on the specified data-target element and expand other divs accordingly. jQuery(document).ready(function() { var windowWidth = jQuery(window).width(); if (win ...

Sending an image using AngularJS to a WCF RESTful service

This particular query has been raised numerous times, and I have extensively researched on Google (primarily stackoverflow), but none of the suggested solutions have worked for me. My goal is to upload an image (base64) to my WCF Service using angularjs. ...

Customize scripts dynamically in Next.js based on the current environment during runtime

I need to dynamically insert a script into the <head> of my application, with the src attribute depending on a runtime environment variable from my hosting server (OpenShift). If process.env.ENVIRONMENT === "test", I want to add <script ...

When using the <a> tag in an ASP.NET MVC view, the hyperlink may be missing

When utilizing ASP.NET MVC 5, I encountered an issue within my view where I am attempting to incorporate "Edit | Delete" functionality within a table. Strangely, I am able to generate a hyperlink for the Edit function, but not for the Delete function. Wit ...

Customize the appearance of an ASP link button within a navigation menu

Just getting started with ASP.net and CSS, I want to customize my link button using CSS similar to other <a href> buttons, but I seem to be running into some issues. This is the code for my menu: <div id="templatemo_menu"> <ul ...

Change the appearance of a specific div within a collection of div elements using React

I'm currently working on a visualizer for sorting algorithms where there are colorful bars that will animate when a specific sorting algorithm is triggered by clicking the play button. To achieve this, I created an array of div elements representing ...

Error in Javascript programming | tracking progress bar

After stumbling upon this code snippet at this link, I was eager to delve deeper into the world of JavaScript and jQuery. However, upon implementing these codes, I encountered a perplexing issue. The progress bar and continue buttons seem to be non-funct ...

Custom CSS for the Google Maps Circle Object

Currently, I am utilizing the Google Maps Javascript API v3 Circle object to display circles on the map. I am interested in customizing the CSS of this circle by incorporating some CSS animations. Although I am aware that custom overlays can be used for t ...

When displaying the date in a dd/MM/yyyy format, Angular mysteriously adds an extra day!

My datepicker saves the selected date without the time in my database, but when I display it, it shows one day ahead. After researching the issue, I found that it's a timezone problem encountered by many people. However, I am not sure how to resolve i ...

iTextSharp struggles to convert certain HTML elements to PDF format

After experimenting with the codes provided in this post, I managed to create the following code snippet: var my_html = this.GetmyReportHtml(); var my_css = this.GetmyReportHtmlCss(); Byte[] bytes; using (var ms = new MemoryStream()) { ...

Running AngularJS controllers should only occur once the initialization process has been fully completed

I am facing a situation where I need to load some essential global data before any controller is triggered in my AngularJS application. This essentially means resolving dependencies on a global level within AngularJS. As an example, let's consider a ...

Rendering elements dynamically using ng-repeat following an AJAX request

Feeling frustrated, I made an $http request ApiService.get_request_params("api/endpoint").then( function(data) { $scope.customers = data }, function(err) { } ); The $scope.customers should be bound to an ng-repeat. I can see the ...

Is there a way to dynamically include an attribute using VueJS?

Is there a way in Vue to dynamically add an attribute, not just the value of an attribute using v-bind? I am aware that I can set a value to an attribute dynamically with v-bind, but I would like to add the attribute itself based on a condition. Something ...

What is the best way to conceal a sticky footer using another element?

I have a footer that remains fixed at the bottom of both long and short pages. Below is the CSS code for this footer: .footer{ position: absolute; bottom: 0; width: 100%; height: 100px; background-color: white; } My goal is to achieve a 'r ...

What enhancements does HTML5 provide for accessibility?

In what ways does HTML5 improve accessibility compared to HTML 4.01 or XHTML 1.0 Strict? ...

Using filter to convert a string into an array and then utilizing it in ng-repeat functionality

I have a string in the format of "1200:2,1300:3,1400:2" that I need to display like this: <p>1200</p><p>2</p> <p>1300</p><p>3</p> <p>1400</p><p>2</p> I attempted to use a filter, ...