only one instance of babel/polyfill is allowed with angular ui-router - angularjs

currently, I work for a school project and want to show some charts with angularJs and meteor.
I want to use the ui-router plugin. But when I try to use it, I get the following error:
Error: only one instance of babel/polyfill is allowed
at Object.eval (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:397:22), <anonymous>:2872:9)
at Object.1.180 (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:397:22), <anonymous>:2875:4)
at s (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:397:22), <anonymous>:2863:254)
at e (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:397:22), <anonymous>:2863:425)
at eval (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:397:22), <anonymous>:2863:443)
at eval (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:397:22), <anonymous>:7043:4)
at eval (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:397:22), <anonymous>:7050:3)
at eval (<anonymous>)
at http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:397:22
at Function.globalEval (http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:398:7) <div ui-view="" class="ng-scope" data-ng-animate="1">
Also I get this warning:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
I have really no idea what this message want to tell me. I didnt load babel/polyfill more than one time. Before I got this message I even didnt know of this plugin.
This is my main.js with the ui-router code:
import angular from 'angular';
import angularMeteor from 'angular-meteor';
import uiRouter from 'angular-ui-router';
import ngMaterial from 'angular-material';
import '../../../node_modules/angular-material/angular-material.css'
import '../own.css';
import template from './main.html';
import { name as Navigation } from '../navigation/navigation';
import {name as Toolbar} from '../toolbar/toolbar';
import {name as View1} from '../view1/view1';
import {name as View2} from '../view2/view2';
class Main {}
const name = 'main';
// create a module
export default angular.module(name, [
angularMeteor,
uiRouter,
Navigation,
Toolbar,
View2,
View1,
ngMaterial
]).component(name, {
template,
controllerAs: name,
controller: Main
})
.config(config);
function config($mdThemingProvider,$urlRouterProvider,$stateProvider ) {
'ngInject';
$urlRouterProvider.otherwise('view1');
$stateProvider
.state('view1', {
url: '/',
templateUrl: 'test.html'
});
$mdThemingProvider
.theme('default')
.primaryPalette('orange')
.accentPalette('deep-orange')
.warnPalette('red');
}
And this is the code of my main.html where the view should be injected:
<div layout="column" style="height: 100%">
<toolbar scroll></toolbar>
<section layout="row" flex>
<navigation></navigation>
<md-content flex layout-padding style="margin-top: 75px">
<div ui-view=""></div>
</md-content>
</section>
Without ui-router it works fine!
What is the problem here?

Most likely you have a module that is requiring babel-polyfill to compile and it's polluting your global namespace with multiple versions of babel. Therefore you want to either tell babel to ignore node_modules directory and or figure out which dependency is requiring babel-polyfill and prevent that.
The final option is to compile the code with the runtime transformer.
https://babeljs.io/docs/plugins/transform-runtime/

I found the solution.
Something was wrong with the $stateprovider.
I copied this code
$stateProvider
.state('view1', {
url: '/',
templateUrl: 'test.html'
});
into the view and changed it to this:
function config($stateProvider) {
'ngInject';
$stateProvider
.state('view1', {
url: '/view1',
template: '<view1></view1>'
});
}
(Last code example is already the finished code from my project). So no more templateUrl, but template now.
I have REALLY no idea why this works, but it works. Maybe there is someone who can explain this?

Try to delete your local file
build/
dist/
However, it works for me.

Related

Angular route error

i trying to do routing for two days but it i can't. I have reviewed the other questions on stackoverflow and i did everything they said in the answers but it wansn't.
I call route script in to index.php
<script src="js/angular-route.js"></script>
I wrote that code in to app.js;
var app = angular.module("app",['ngRoute']);
app.config(function($routeProvider){
$routeProvider.
when('/', {
templateUrl:'pages/home.php'
}).
when('/notificastions', {
templateUrl:'pages/notifications.php'
}).
when('/messages', {
templateUrl:'pages/messages.php'
}).
when('/search', {
templateUrl:'pages/search.php'
}).
otherwise({
rediectTo: '/'
})
})
I wrote that codes in to a page with i connect ng-include:
<div id="ifmenu">
<div class="ifmitem" href="#/home">Home</div>
<div class="ifmitem" href="#/notifications">Notifications</div>
<div class="ifmitem" href="#/messages">Messages</div>
</div>
<div ng-view></div>
But i get an error like this;
Uncaught Error: [$injector:unpr]
http://errors.angularjs.org/1.2.32/$injector/unpr?p0=%24templateRequestProvider%20%3C-%20%24templateRequest%20%3C-%20%24route
at angular.min.js:6
at angular.min.js:36
at Object.c [as get] (angular.min.js:34)
at angular.min.js:36
at c (angular.min.js:34)
at Object.d [as invoke] (angular.min.js:35)
at angular.min.js:36
at Object.c [as get] (angular.min.js:34)
at instantiateRoute (angular-route.js:886)
at Object.d [as invoke] (angular.min.js:35)
How do i resolve this error?
I resolve 'Uncaught Error: [$injector:unpr]' error, but have exclamation mark beside hashtag. Like this: (localhost/app/#!). And none of link doesn't working except the otherwise function.
I called solution of this problem in internet and i saw that i need to attach and i added;
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
But none of them doesn't working this time. What should I do to solve this problem?
Your notifications spelling is wrong.see the routeProvider section
when('/notificastions', {
templateUrl:'pages/notifications.php'
})
notificastions should be notifications

Simple Example Using Angular 1 with TypeScript and SystemJS

I have been trying to convert a TypeScript Angular 1 application to use ES6 style module imports.
Dropping the use of namespace and using the import keyword to pull in modules. e.g.
import * as angular from "angular";
import * as angularroute from "angular-route";
But I have run into some issues.
I'm getting an error from angular:
Uncaught (in promise) Error: (SystemJS) [$injector:modulerr] Failed to instantiate module testApp due to:
Error: [$injector:modulerr] Failed to instantiate module ngRoute due to:
Error: [$injector:nomod] Module 'ngRoute' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument
To illustrate the issue, I have created two applications on github:
1) Angular1WithNamespaces- Original app that I want to convert.
2) Angular1WithSystemJS - My Conversion, that has an issue.
Below are snippets from the Angular1WithSystemJS example that has the issue.
index.html
<!DOCTYPE html>
<html lang="en" ng-app="testApp">
<head><base href="/"></head>
<body >
<ng-view></ng-view>
<script src="node_modules/systemjs/dist/system.js"></script>
<script src="configs/systemjs.config.js"></script>
<script>
System.import('app/boot');
</script>
</body>
</html>
systemjs.config.js
System.config({
defaultJSExtensions: true,
paths: {
"npm:*": "../node_modules/*"
},
// map tells the System loader where to look for things
map: {
"angular": "npm:angular/angular.js",
"angular-route": "npm:angular-route/angular-route.js",
},
meta: {
'angular': {
format: 'global',
},
'angular-route': {
format: 'global',
},
}
});
boot.ts
/// <reference path="../typings/tsd.d.ts" />
import * as angular from "angular";
import * as angularroute from "angular-route";
let main = angular.module("testApp", ["ngRoute"]);
main.config(routeConfig)
routeConfig.$inject = ["$routeProvider"];
function routeConfig($routeProvider: angular.route.IRouteProvider): void {
$routeProvider
.when("/dashboard", {
templateUrl: "/app/dashboard.html",
})
.otherwise("/dashboard");
}
Any help getting this working would be greatly appreciated.
I have found a solution by reading a blog post from https://legacy-to-the-edge.com/2015/01/21/using-es6-with-your-angularjs-project/
It was related to how I did the import for angular-route.
In the end it was just a one-liner change.
In boot.ts I changed the import statement from:
import * as angularroute from "angular-route";
to:
import "angular-route";
I can only assume, that the latter will also run scripts in the module file.
According to the spec on import at developer.mozilla.org
import "my-module";
Import an entire module for side effects only, without importing any bindings.
The fixed version is in github Angular1WithSystemJSFixed

Using factories in AngularUI Route?

I'm writing an Ionic app, which uses AngularUI's Router. I'd like to query localstorage using a factory I wrote, so I can determine whether to show a first-run screen or not.
My index.html loads scripts in this order:
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
<script src="js/routes.js"></script>
<script src="js/directives.js"></script>
<script src="js/filters.js"></script>
And my routes config looks like this (truncated for brevity):
angular.module('app.routes', [])
.config(function($stateProvider, $urlRouterProvider, storageFactory) {
$stateProvider
.state('myApp.mainscreen', {
url: '/main',
views: {
'side-menu21': {
templateUrl: 'templates/main.html',
controller: 'mainCtrl'
}
}
})
// ...
$urlRouterProvider.otherwise('/menu/main')
Now I have a module called app.services, which contains my factory, storageFactory (I know, I'm going to move it out of the services module ;)). When I attempt to inject storageFactory like so:
angular.module('app.routes', ['app.services', 'storageFactory'])
.config(function($stateProvider, $urlRouterProvider, storageFactory) {
I get an error similar to this:
Error: [$injector:nomod] Module 'storageFactory' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
I'm certain that my app has loaded app.services and storageFactory prior to loading, but I just can't seem to get it to work correctly.
How can I resolve this?
You can inject factories in UI router resolve blocks, without injecting them in the config block since it can only be injected with providers. For example:
$stateProvider
.state('myApp.mainscreen', {
url: '/main',
views: {
'side-menu21': {
templateUrl: 'templates/main.html',
controller: 'mainCtrl'
}
},
resolve: {
firstRun: ['storageFactory', function(storageFactory) {
// Do what you want with storageFactory here!
// Full infos here: https://github.com/angular-ui/ui-router/wiki#resolve
}]
}
})
you cant inject services in config only provides but you can do it in app.run Here's the calling order:
app.config() //only provides can be injected
app.run()
directive's compile functions (if they are found in the dom)
app.controller()
directive's link functions (again, if found)
in your case you can also use route resolve property

ui-router resolve failing after injecting property into controller

I'm not sure what I'm doing wrong. I'm getting this error
Error: [$injector:unpr] http://errors.angularjs.org/1.2.21/$injector/unpr?p0=propertyUserDataProvider%20%3C-%20propertyUserData
at Error (native)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:6:450
at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:36:145
at Object.c [as get] (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:34:236)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:36:213
at c (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:34:236)
at d (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:34:453)
at Object.instantiate (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:35:103)
at $get (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:67:253)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:53:362 <div ui-view="performance-ui-view" class="ng-scope">
Here is my code:
// the controller
app.controller('GlobalDashboardController', ['propertyUserData', function(propertyUserData) {
}])
// ui-router snippet
.state("main", {
url: "/",
views: {
'' : { templateUrl: 'views/main.html' },
'performance-ui-view#main': {
templateUrl: 'views/gdreport.html',
controller : 'GlobalDashboardController',
resolve: {
propertyUserData : function() {
return 'test';
}
}
}
}
})
Right now, I'm returning the string 'test' so I can debug. I do have a User service which I will use once the error is fixed. However, I'm really confused as to why it's failing. Once I remove resolve and the dependency injection in the controller, my application starts working fine again.
You should remove ng-controller directive from your partial view gdreport.html since you have specified the controller in the route itself, it will instantiate and bind the controller to the partial view. And you cannot instantiate this controller yourself because of the dynamic dependency provided via resolve property can only be injected by the router. And your error reflects exactly what it means, i.e propertyUserData provider does not exist.

Unknown provider error on btfModal

I'm using Brian Ford's angular-modal library to provide modals for my app. It works properly in development, but minification seems to break it even though I'm using ngmin through a gulp build process.
Error: [$injector:unpr] Unknown provider: tProvider <- t <- btfModal <- deleteConfirmationModal
http://errors.angularjs.org/1.2.17-build.225+sha.9227a5d/$injector/unpr?p0=tProvider%20%3C-%20t%20%3C-%20btfModal%20%3C-NaNeleteConfirmationModal
at http://localhost:3005/live/vendors.min.js:1:697
at http://localhost:3005/live/vendors.min.js:1:17123
at Object.n [as get] (http://localhost:3005/live/vendors.min.js:1:16388)
at http://localhost:3005/live/vendors.min.js:1:17218
at n (http://localhost:3005/live/vendors.min.js:1:16388)
at Object.r [as invoke] (http://localhost:3005/live/vendors.min.js:1:16673)
at http://localhost:3005/live/vendors.min.js:1:17236
at n (http://localhost:3005/live/vendors.min.js:1:16388)
at Object.r [as invoke] (http://localhost:3005/live/vendors.min.js:1:16673)
at http://localhost:3005/live/vendors.min.js:1:17236
Based on what I've read in general about Unknown provider errors, I'm sure it’s a problem with dependency injection. I've tried every permutation I can think of, but I can't make it work.
Here's the pertinent code:
Creates the module:
angular.module('gridsmartWebClient.modal', ['btford.modal']);
Factory:
angular.
module('gridsmartWebClient.modal')
.factory('deleteConfirmationModal', function (btfModal) {
'use strict';
return btfModal({
controller: 'DeleteModalCtrl',
controllerAs: 'modal',
templateUrl: '/gridsmart-web-client/camera/delete-confirmation.html'
});
})
Factory after ngmin:
angular.module('gridsmartWebClient.modal').factory('deleteConfirmationModal', [
'btfModal',
function (btfModal) {
'use strict';
return btfModal({
controller: 'DeleteModalCtrl',
controllerAs: 'modal',
templateUrl: '/gridsmart-web-client/camera/delete-confirmation.html'
});
}
])
App dependencies:
angular.module('gridsmartWebClient', [
'ngRoute',
'gridsmartWebClient.grid',
'gridsmartWebClient.camera',
'gridsmartWebClient.modal',
'gridsmartWebClient.utils',
'dropdownDirective',
'btford.modal',
'gridsmart-web-client-templates'
])
So, despite the fact I know there's a problem with dependency injections, I can't see what it would be. The module the factory is declared in has been injected in the app. I've looked through other responses to similar questions but answers are either very specific to the respective scenarios or general so as not to be especially useful to me. (e.g. "It's a dependency problem."). What gives?
The problem is in vendors.min.js, not your code. You need ngmin all your vendor scripts as well.

Resources