AngularJS app does not load on iPad / iPhone Safari (works only after page refresh / second load and afterwards) - angularjs

I have a really weird issue with my AngularJS app on iPad / iPhone safari.
The issue occurs only of first load (after clearing history / website data).
The issue that the application wont start at all - I get a white page and the console (from MacBook develop tools) is full with errors,
Sometimes I'm getting lots of
TypeError: undefined is not an object (evaluating 'd.module')
ReferenceError: Can't find variable: angular
TypeError: undefined is not an object (evaluating 'd.$$minErr')
ReferenceError: Can't find variable: angular
TypeError: undefined is not an object (evaluating 't.noop')
ReferenceError: Can't find variable: angular
ReferenceError: Can't find variable: angular
...
Sometimes I'm getting Error: $injector:unpr - Unknown Provider
And sometimes Error: $injector:nomod - Unknown Provider
But if I hit page refresh after getting the white page / errors - all works just fine.
This is part of the third party js libs/plugins I include on my index.html
<script src="resources/plugins/head.load.min.js"></script>
<script src="resources/plugins/modernizr-custom.js"></script>
<script src="resources/lib/jquery/jquery-2.1.0.min.js"></script>
<script src="resources/lib/angular/angular.min.js"></script>
<script src="resources/lib/angular/angular-resource.min.js"></script>
<script src="resources/lib/angular/angular-route.min.js"></script>
<script src="resources/lib/angular/angular-animate.min.js"></script>
<script src="resources/lib/angular-translate/angular-translate.min.js"></script>
<script src="resources/lib/angular-translate/angular-translate-loader-static-files.js"></script>
<script src="resources/lib/angular-ui/ui-bootstrap-custom-tpls-0.14.1.min.js"></script>
<script src="resources/lib/ng-table/ng-table.min.js"></script>
<script src="resources/lib/file-upload/ng-file-upload-shim.min.js"></script>
<script src="resources/lib/file-upload/ng-file-upload.min.js"></script>
I'm really lost here...
Another thing: I have noticed on my Mac (Resources->Scripts) that if I open a file, lets say Resources->Scripts->FileNameOne.js the content is actually of another file FileNameTwo.js ??? is it a flaw of the dev tools of the Mac that confuses the names/content or can it be related to the problem???
Any Ideas?
Here is the complete solution with Grunt
Content of the Gruntfile.js
'use strict';
module.exports = function(grunt){
grunt.initConfig({
concat: {
dist: {
src: ['WebContent/resources/plugins/head.load.min.js', 'WebContent/resources/plugins/modernizr-custom.js',
'WebContent/resources/lib/jquery/jquery-2.1.0.min.js',
'WebContent/resources/lib/angular/angular.min.js', 'WebContent/resources/lib/angular/angular-resource.min.js', 'WebContent/resources/lib/angular/angular-route.min.js', 'WebContent/resources/lib/angular/angular-animate.min.js',
'WebContent/resources/lib/angular-translate/angular-translate.min.js', 'WebContent/resources/lib/angular-translate/angular-translate-loader-static-files.js',
'WebContent/resources/lib/angular-ui/ui-bootstrap-custom-tpls-0.14.1.min.js',
'WebContent/resources/lib/ng-table/ng-table.min.js',
'WebContent/resources/lib/websockify/util.js', 'WebContent/resources/lib/websockify/base64.js', 'WebContent/resources/lib/websockify/websock.js',
'WebContent/resources/lib/file-upload/ng-file-upload.min.js',
'WebContent/resources/js/services/*',
'WebContent/resources/js/services/dialogs/*',
'WebContent/resources/js/controllers/*',
'WebContent/resources/js/directives/*',
'WebContent/resources/plugins/*'],
dest: 'dist/myWebAppInOneFile.js',
},
},
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.registerTask('default', ['concat']);
};
Then just call grunt from the relevant folder and you'll get your file

What build toolchain are you using. One option would be to concatenate all of the includes into a single file, this should stop the error where the wrong scripts are being loaded - As mentioned by Marcus H
Gulp
https://github.com/contra/gulp-concat
Grunt
https://github.com/gruntjs/grunt-contrib-concat

Related

angularjs directive not being loaded when angularjs-dragula package is required

I am in the process of migrating our .NET Framework project over to .NET Core. And where we previously relied on the BundleTable tools in .NET Framework. We are now using webpack.
I have a directive that uses a package 'angularjs-dragula'. The webpack entry definition is as follows
'bundles/grouping':
[
"./Scripts/angularjs-dragula.js",
"./App/components/grid.directive.js",
"./App/components/inline-edit.directive.js",
"./App/services/grouping.service.js",
"./App/components/grouping/grouping.directive.js"
],
I initialize the directive as follows:
(function () {
angular.module('App').requires.push(angularDragula(angular));
angular
.module('App')
.directive('appCustomGrouping', appCustomGrouping);
appCustomGrouping.$inject = ['urlService', 'groupingService', 'dragulaService' ];
function appCustomGrouping(urlService, groupingService, dragulaService) {
...
As it is, the page never loads grouping.directive. And there are no errors. Unless i remove the dragula file in the webpack entrypoint. The directive will then load, but complain:
ReferenceError: angularDragula is not defined[Learn More]
I have tried relying on webpack to import the package, and removed it from the entry definition. I installed angularjs-dragula into my node_modules, and used
var angularDragula = require('angularjs-dragula');
(function () {
angular.module('App').requires.push(angularDragula(angular));
angular
.module('App')
.directive('appCustomGrouping', appCustomGrouping);
appCustomGrouping.$inject = ['urlService', 'groupingService', 'dragulaService' ];
function appCustomGrouping(urlService, groupingService, dragulaService) {
...
However this results in the same behavior.
The angularjs-dragula package works, since we were using it before the move to webpack. However now it seems to be silently failing, and taking the rest of the directive with it?
How can I begin to diagnose this issue?
The AngularJS wrapper for Dragula is unusual in that it places on global scope a function named angularDragula. That function registers the dragula module with AngularJS when the function is invoked with angular as an argument. It returns a string with the module name "dragula".
angularDragula(angular)
angular.module("app",["dragula"])
.run(function(dragulaService) {
console.log(dragulaService);
})
<script src="//unpkg.com/angular/angular.js"></script>
<script src="//unpkg.com/angularjs-dragula/dist/angularjs-dragula.js"></script>
<body ng-app="app">
<h1>Hello AngularJS!</h1>
</body>
the page never loads grouping.directive
How can I begin to diagnose this issue?
I would use the Developer Console to insert breakpoints. Then examine variables.
The above example loads AngularJS with Dragula and successfully logs the dragularService.

Cannot load my ui-calendar module

When i try to load my ui-calendar in my angular.module i am getting Uncaught Error: Injector error. How will i include my ui-calendar. I am using npm install.
This is my error:
Uncaught Error: [$injector:modulerr]
at angular.js:38
at angular.js:4408
at n (angular.js:336)
at g (angular.js:4369)
at eb (angular.js:4294)
at d (angular.js:1655)
at yc (angular.js:1676)
at Zd (angular.js:1570)
at HTMLDocument.<anonymous> (angular.js:28683)
at j (jquery.js:3148)
This is my module were i am including ui-calendar:
var ebsapp = angular.module("ebs", ['ui.bootstrap', 'angular.filter', 'toastr', 'ui.calendar']);
Or is there any other script tags that needed to be included. if so please give me the script tags.
My injector error got resolved. I want to get a full calendar view.
I am using this div code:
<div ui-calendar ng-model="eventSources"></div>
How to get a simple calendar view??
Is these are the scripts i need to load ??
<link rel='stylesheet' href='fullcalendar/fullcalendar.css' />
<script src='lib/jquery.min.js'></script>
<script src='lib/moment.min.js'></script>
<script src='fullcalendar/fullcalendar.js'></script>
I tried to implement form https://jsfiddle.net/yy1rud17/326/ website where in i got the following out;
Whether i need to initialise my calendar??

Angular2 in JSP ( Spring MVC )

My question is similar to this existing question i.e. A Web project is already using - Spring MVC + Angular1.x + JSP + JavaScript etc.
Page layout is already designed with tiles technology and I have to develop a sample page - only body part i.e. I have to keep doing layout with tiles and have to reuse - header , footer , left navigation etc .
So I set up a separate Angular2 project , build it and included final JS files in layout JSP of tiles.
In my new body jsp, when I use angular2 root component , my jSP is displaying perfectly but all other pages of application are showing this below error,
core.es5.js:1020 ERROR Error: The selector "app-root" did not match any elements
at DefaultDomRenderer2.selectRootElement (platform-browser.es5.js:2791)
at createElement (core.es5.js:9172)
at createViewNodes (core.es5.js:12146)
at createRootView (core.es5.js:12075)
at Object.createProdRootView [as createRootView] (core.es5.js:12760)
at ComponentFactory_.create (core.es5.js:9858)
at ComponentFactoryBoundToModule.create (core.es5.js:3333)
at ApplicationRef_.bootstrap (core.es5.js:4763)
at core.es5.js:4546
at Array.forEach (<anonymous>)
defaultErrorLogger # core.es5.js:1020
zone.js:654 Unhandled Promise rejection: The selector "app-root" did not match any elements ; Zone: <root> ; Task: Promise.then ; Value: Error: The selector "app-root" did not match any elements
at DefaultDomRenderer2.selectRootElement (platform-browser.es5.js:2791)
at createElement (core.es5.js:9172)
at createViewNodes (core.es5.js:12146)
at createRootView (core.es5.js:12075)
at Object.createProdRootView [as createRootView] (core.es5.js:12760)
at ComponentFactory_.create (core.es5.js:9858)
at ComponentFactoryBoundToModule.create (core.es5.js:3333)
at ApplicationRef_.bootstrap (core.es5.js:4763)
at core.es5.js:4546
at Array.forEach (<anonymous>) Error: The selector "app-root" did not match any elements
at DefaultDomRenderer2.selectRootElement
This above error is on console and those other JSP pages keep working correctly and this background error affects them in no way.
This error doesn't come on JSP page where I call root component i.e. my new jsp body page.
I have included angualr2 JS files outside outside body tag at bottom.
Any suggestions to remove this error from console and if this set up looks OK?
We will set up an automated process to build and copy files from Angualr2 UI project to Spring MVC project and only those final JS files will be deployed with app.
Its an Spring MVC controller which loads the page for the first time - a JSP .
With inputs from JB Nizet from comments , I am able to resolve issue by removing angular js inclusions from common application layout JSP and putting it in body jsp file as shown below.
<app-root>Loading...</app-root>
<!-- For Angular 2 -->
<script type="text/javascript" src="inline.bundle.js" ></script>
<script type="text/javascript" src="polyfills.bundle.js" ></script>
<script type="text/javascript" src="styles.bundle.js" ></script>
<script type="text/javascript" src="vendor.bundle.js" ></script>
<script type="text/javascript" src="main.bundle.js" > </script>
I am building application with - ng build --env=prod --output-hashing none
I if I do JS inclusions before calling root component, error occurs.

ngDrive not defined?

This question is a follow up to Definition for gapi in an Angular controller? which is posted yesterday.
User pinoyyid pointed me to his git repo ngDrive (https://github.com/pinoyyid/ngDrive)
I was working through the quit start and ran into an error saying 'ngDrive' is not defined in my console.
This was the code that cause this error
angular.module('ngm.ngDrive')
.provider('OauthService', ngDrive.Config)
.config(function (OauthServiceProvider) {
OauthServiceProvider.setScopes('https://www.googleapis.com/auth/drive.file');
OauthServiceProvider.setClientID('2231299-2bvf1.apps.googleusercontent.com');
OauthServiceProvider.setTokenRefreshPolicy(ngDrive.TokenRefreshPolicy.ON_DEMAND);
OauthServiceProvider.setNoAccessTokenPolicy(999); // 0 = fail, > 0 = retry after x
});
Specifically the ngDrive.Config
I had no issue when injecting the service into my app.js file as shown below
angular
.module('App', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch',
'ui.sortable',
'firebase',
'angular-toArrayFilter',
'ngm.ngDrive'
])
I have also placed the script tag for the library as specified:
<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="bower_components/ngDrive/build/module.js"></script>
<script src="scripts/app.js"></script>
<script src="scripts/controllers/login_controller.js"></script>
<script src="scripts/controllers/view_resources_ctrl.js"></script>
<!-- endbuild -->
I'm not quite sure what I'm doing wrong here. I don't see anything in the guide that I might have accidentally skipped.
Thanks for your time.
I did bower install ngDrive --save, included <script src="../bower_components/ngDrive/build/module.js"></script> (my index.js is in an app folder) before app.js, injected the ngm.ngDrive, copy-pasted the .provider('OauthService', ngDrive.Config). Then I added into config,
OauthServiceProvider.setScopes('https://www.googleapis.com/auth/drive.file');
OauthServiceProvider.setClientID('2231299-2bvf1.apps.googleusercontent.com');
OauthServiceProvider.setTokenRefreshPolicy(ngDrive.TokenRefreshPolicy.ON_DEMAND);
OauthServiceProvider.setNoAccessTokenPolicy(999);
Nothing complained about ngDrive.Config. But I do get errors:
Failed to load resource: the server responded with a status of 404 (Not Found): http://localhost:3000/bower_components/ngDrive/build/module.js.map (resource that I did not explicitly request for loading)
OauthServiceProvider.setNoAccessTokenPolicy is not a function. (In 'OauthServiceProvider.setNoAccessTokenPolicy(999)', 'OauthServiceProvider.setNoAccessTokenPolicy' is undefined). (checked the source and It seems this method does not exist in the current version of the module)
I tried but can't reproduce your error.
The 'ngDrive' is not defined is caused by module.js failing to load. If you look at the network tab, you'll see a 404.
Also, there is a bug in the documentation, setNoAccessTokenPolicy is no longer a feature, so you should delete that line. Version 0.1.10 fixes the documentation.

Angular JS script files loading sequence erroring?

I have a file "A.js" in which I have a initialised a module as given below
angular.module("x", []);
I have another file "B.js" in which also I have initialised a module as give below, in this case it is dependent on the "x" module as defined above in A.js
angular.module("y", ["x"]);
Now in the html file I have declared the script files as given below -
<script src = "B.js" ></script>
<script src = "A.js" ></script>
On loading the application, I am getting below error -
"Uncaught Error: [$injector:unpr] ..."
Question - Is the above error because the sequence in the HTML file should have been, first load A.js and then B.js since "y" module in B.js is dependent on "x" module in A.js?
Note - I have checked all the other probable places which could have caused the error, they are all fine. I am left with the above question only.

Resources