How come my AngularJS view isn't loading properly on Cordova?

Looking at my index.html, it appears as follows:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>Hello World</title>
  </head>
  <body ng-app="app">
    THIS WORKS NOW!
    <div ng-view></div>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/angular.min.js"></script>
    <script type="text/javascript" src="js/angular-route.min.js"></script>
    <script type="text/javascript" src="js/app.js"></script>
  </body>
</html>

In my app.js file, this is the setup I have:

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

app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
    $routeProvider.when('/', {
      templateUrl: 'templates/home.html'
    }).when('/dashboard', {
      templateUrl: '/templates/dashboard.html'
    }).otherwise({
      redirectTo: '/'
    });

    $locationProvider.html5Mode(true);
  }
]);

After running cordova build ios and opening the Xcode project to run, I can see the text "THIS WORKS NOW!" displayed on screen. However, the contents of my home.html file are not showing up.

What could be causing this issue?

Answer №1

To successfully integrate bootstrap with angular, follow these steps:

app.js is good to go!

However, make sure to remove the ng-app attribute from within the <body> tag and initiate angular once the onDeviceReady event is triggered :

Update your index.js file:

var app = {
    initialize: function () {
        this.bindEvents();
    },
    bindEvents: function () {
        document.addEventListener("deviceready", this.onDeviceReady, false);
    },
    onDeviceReady: function () {
        angular.element(document).ready(function () {

            angular.bootstrap(document, ["app"]);

        });
    }
};

Following these instructions should set you up for success.

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

Should the use of readFileSync() during the initialization of a Node.js web application be avoided?

I have a Node app that serves web pages with static HTML-snippet files included conditionally. I am considering implementing a cache map for these snippets by adding the following code to my Express's app.js file: var cache = Object.create(null); cac ...

Creating a Google Captcha with validation is a straightforward process that can enhance the

I am having issues with adding Google Captcha to my form. Despite all fields working properly, the Captcha integration seems to be causing some disruptions. I have included my code below. Thank you in advance for your help. Please also check the following ...

Solution for dropdown boxes malfunctioning with required fields

Using Bootstrap 3 for field validation on forms has been effective, but there seems to be an issue with certain browsers such as ios safari not validating [required] form items. To address this, I created a script that checks if an element is marked as req ...

Page not loading Ajax function upon initialization

I am currently experimenting with this: https://github.com/derekmartinez18/Simple-Ajax-Spotify-Now-Playing and have created a simple function to display my Spotify listening activity: function get_spotify() { $.ajax({ type: 'POST', url: ...

Best method for retrieving information from a string

Exploring different techniques to extract data from a string is a common practice, including methods like substring and split. Is there an optimal approach to accomplish this task? For instance, when faced with a URL structure such as http://myServer:8000/ ...

Only perform the Rails ajax call once initially

I'm currently working on creating a drop down menu that contains a substantial amount of content, and I would like to use an ajax get call to load everything upon mouse enter. Here is my code written in coffeescript: class @SecondaryMenu construct ...

Could this be considered a typical trend - opting to return data instead of a promise?

I recently came across a new approach while reading 'Mean Machine'. Typically, I have always been taught to return a promise from a service to the controller and then handle it using .success or .then. In this case, the author is directly retur ...

Transform a protractor screenshot into a PDF file

I'm currently working on a small Protractor code that captures screenshots, but my goal is to save these screenshots as PDF files. Below you can find the code snippet I have written. await browser.get(url); const img = await browser.takeScreenshot(); ...

Error encountered while adding the Cordova platform, specifically with Android

Whenever I attempt to execute cordova platform add android, whether it's coming from an Ionic or Cordova Project, the following error pops up: /c/Users/USERNAME/AppData/Roaming/npm/cordova: line 14: 1200 Illegal instruction node "$basedir/node_m ...

Is there a way to trigger a Modal to open upon clicking a custom-designed button in MaterialUI?

In my React and Material-UI project, I am attempting to trigger a Modal to open using a custom button. The button also performs other functions, which is why it's important for me to combine the "Modal Opening" action with these additional functionali ...

What exactly is the functionality of the jQuery.on() method?

I am curious about the functionality of this function and how it operates. Does it follow these steps: Identify element(s) using their selectors Assign event-handlers to them Execute a setInterval on that selector, consistently delegating and then undeleg ...

Creating an object key using a passed literal argument in TypeScript

Can the following scenario be achieved? Given an argument, how can we identify the object key and access it? Any potential solutions? async function checkKey(arg:'key1'|'key2'){ // fetchResult returns an object with either {key1:&apo ...

Having trouble with your YouTube Live Stream not playing in the React Player version 2.9.0?

I successfully integrated react-player into my react.js website and it was working perfectly. However, after a few days, it suddenly stopped functioning. Even updating the plugin to version 2.9.0 did not resolve the issue. Strangely enough, standard YouTub ...

Having trouble with Vue component not updating Vuex state before it loads?

At times, the token is committed to Vuex store while other times it is not. userLogin() { axios.post('api/login', this.logindata,) .then(response => { let token = JSON.parse(localStorage.getItem('token')); t ...

I'm having trouble getting FlowType.js to function properly

I have added the following code just before the closing </body> tag, but unfortunately, it seems like the type is not changing as expected. I am struggling to identify what mistake I might be making. Check out FlowType.JS on GitHub View the code on ...

Approach for customizing Mashape API key in Swift

I recently attempted to utilize the "Yoda Speak" API by Mashape, only to receive binary data that I am unable to parse. Upon trying to print the data, I received the following error message: "(message, Missing Mashape application key. Go to to get your ke ...

Leverage infrared technology to detect objects on an iOS or Android device

What is the best way to program infrared detection on an iOS or Android device to detect the presence of a real object within the IR range? ...

Encountering a problem when trying to create a node in Neo4j using Node.js

Here is my code for a Node.js application using Neo4j: var neo4j = require('neo4j-driver').v1; var express = require('express'); var logger = require('morgan'); var path = require('path'); var bodyParser =require(&a ...

Display various elements depending on the size of the screen within Next.js

My goal is to display a component differently depending on whether the screen width is less than 768p or not. If the width is under 768p, I want to show the hamburger menu. Otherwise, I want to display the full menu. This is the code snippet I am using. ...

How can I retrieve a specific set of Firebase documents based on a property's value in a collection?

I'm currently developing a social media app using Firebase and React, and I need to implement a search bar that suggests users based on the input value. For example, when typing "F," I want to see suggestions like Foo and Bar, similar to common social ...