Getting type error while Implementing hereMap Api - angular7

I'm trying to add maps via hereMaps Api in my webApplication which is in Angular7 .While creating platform using service module which is
this.platform = new H.service.Platform({
"app_id": "{9qrlA6ZVcLPDw16Mkclk}",
});
I'm getting following saying ,
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'service' of undefined
TypeError: Cannot read property 'service' of undefined
i have installed npm here-js-api package and also declared service module
<script src="https://js.api.here.com/v3/3.0/mapsjs-core.js" type="text/javascript" charset="utf-8"></script>
in src/index.html .but still i'm getting the same type error.!
Any solutions?

Add your script file to your angular.json in the script section
"scripts": [
...
"./node_modules/heremap/dist/heremap.min.js",
"./node_modules/heremap/dist/libhere.min.js",
]
Then styles in syle section
"styles": [
...
"./node_modules/heremap/css/heremap.css",
]
Now you have to declare Heremap from window and then use it:
declare const hm = window.heremap;
export class YourService {
// Now you can use hm
// eg.
hm.config({
app_id: APP_ID,
app_code: APP_CODE,
});
hm.getAvailableMapStyle().then(style => {
console.log("Style ", style);
});
// show map fragment
// to see console message, open debugger window
hm.map(
"map", {
zoom: 6,
scheme:"satellite.day",
viewChange: (zoom, coord) => {
console.log("viewchange", zoom, coord)
},
click: (coord, button, key) => {
console.log("click", coord, button, key)
},
keydown: (key) => {
console.log("key down", key)
}
}
);
}

Related

Electron ES6 module import

Electron 3.0.0-beta.1
Node 10.2.0
Chromium 66.0.3359.181
The problem I'm having is importing a module. I created the following protocol:
protocol.registerFileProtocol('client', (request, callback) => {
var url = request.url.substr(8);
callback({path: path.join(__dirname, url)});
});
The output of the protocol is the correct path
"/Users/adviner/Projects/Client/src/ClientsApp/app.js"
I have the following module app.js with the following code:
export function square() {
return 'hello';
}
in my index.html I import the module like so:
<script type="module" >
import square from 'client://app.js';
console.log(square());
</script>
But I keep getting the error:
app.js/:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
I'm done searches but can't seem to find a solution. Can anyone suggest a way I can make this work?
Thanks
This is a tricky question and i will refer to Electron#12011 and this GitHub Gist for a deeper explaination but the core learning is that the corresponding HTML spec, disallows import via file:// (For XSS reasons) and a protocol must have the mime types defined.
The file protocol you use client:// has to set the correct mime-types when serving the files. Currently i would guess they are not set when you define the protocol via protocol.registerBufferProtocol thus you recive a The server responded with a non-JavaScript MIME type of "", the gist above has a code sample on how to do it.
Edit: I just want to emphasize the other answers here do only cover the absolute minimum basics implementation with no consideration of exceptions, security, or future changes. I highly recommend taking the time and read trough the gist I linked.
To confirm: this is there for security reasons.
However, in the event that you just need to get it deployed:
Change "target": "es2015" to "target": "es5" in your tsconfig.json file
Quick Solution:
const { protocol } = require( 'electron' )
const nfs = require( 'fs' )
const npjoin = require( 'path' ).join
const es6Path = npjoin( __dirname, 'www' )
// <= v4.x
// protocol.registerStandardSchemes( [ 'es6' ] )
// >= v5.x
protocol.registerSchemesAsPrivileged([
{ scheme: 'es6', privileges: { standard: true } }
])
app.on( 'ready', () => {
protocol.registerBufferProtocol( 'es6', ( req, cb ) => {
nfs.readFile(
npjoin( es6Path, req.url.replace( 'es6://', '' ) ),
(e, b) => { cb( { mimeType: 'text/javascript', data: b } ) }
)
})
})
<script type="module" src="es6://main.js"></script>
Based on flcoder solution for older Electron version.
Electron 5.0
const { protocol } = require('electron')
const nfs = require('fs')
const npjoin = require('path').join
const es6Path = npjoin(__dirname, 'www')
protocol.registerSchemesAsPrivileged([{ scheme: 'es6', privileges: { standard: true, secure: true } }])
app.on('ready', async () => {
protocol.registerBufferProtocol('es6', (req, cb) => {
nfs.readFile(
npjoin(es6Path, req.url.replace('es6://', '')),
(e, b) => { cb({ mimeType: 'text/javascript', data: b }) }
)
})
await createWindow()
})
Attention! The path always seems to be transformed to lowercase
<script type="module" src="es6://path/main.js"></script>
Sorry Viziionary, not enough reputation to answer the comment.
I've now done it like this:
https://gist.github.com/jogibear9988/3349784b875c7d487bf4f43e3e071612
my problem was, I also wanted to support modules which are imported via none relative path's, so I don't need to transpile my code.

ng-token-auth errors - preventing app from loading

I have an AngularJs + Ruby on Rails app and I'm trying to integrate ng-token-auth, however I am getting the following warning and errors when my app loads, preventing the app from actually loading:
jQuery.Deferred exception: Cannot read property 'validateOnPageLoad' of
undefined TypeError: Cannot read property 'validateOnPageLoad' of
undefined
-
TypeError: Cannot read property 'proxyIf' of undefined
at Object.apiUrl (ng-token-auth.self-50017ec….js?body=1:689)
at ng-token-auth.self-50017ec….js?body=1:789
at Object.invoke (angular.self-5592af5….js?body=1:4626)
at request (ng-token-auth.self-50017ec….js?body=1:786)
at processQueue (angular.self-5592af5….js?body=1:15758)
at angular.self-5592af5….js?body=1:15774
at Scope.$eval (angular.self-5592af5….js?body=1:17026)
at Scope.$digest (angular.self-5592af5….js?body=1:16842)
at angular.self-5592af5….js?body=1:17065
at completeOutstandingRequest (angular.self-5592af5….js?
body=1:5825)
-
TypeError: Cannot read property 'url' of undefined
at ng-token-auth.self-50017ec….js?body=1:815
at Object.invoke (angular.self-5592af5….js?body=1:4626)
at responseError (ng-token-auth.self-50017ec….js?body=1:813)
at processQueue (angular.self-5592af5….js?body=1:15758)
at angular.self-5592af5….js?body=1:15774
at Scope.$eval (angular.self-5592af5….js?body=1:17026)
at Scope.$digest (angular.self-5592af5….js?body=1:16842)
at angular.self-5592af5….js?body=1:17065
at completeOutstandingRequest (angular.self-5592af5….js?
body=1:5825)
at angular.self-5592af5….js?body=1:6101
-
Uncaught TypeError: Cannot read property 'validateOnPageLoad' of undefined
at Object.addScopeMethods (ng-token-auth.self-50017ec….js?
body=1:168)
at Object.initialize (ng-token-auth.self-50017ec….js?body=1:109)
at ng-token-auth.self-50017ec….js?body=1:836
at Object.invoke (angular.self-5592af5….js?body=1:4626)
at angular.self-5592af5….js?body=1:4434
at forEach (angular.self-5592af5….js?body=1:322)
at createInjector (angular.self-5592af5….js?body=1:4434)
at doBootstrap (angular.self-5592af5….js?body=1:1711)
at bootstrap (angular.self-5592af5….js?body=1:1732)
at angularInit (angular.self-5592af5….js?body=1:1617)
here's my app index and auth config:
(function(){
'use strict';
angular.module('MyApp', [
'restangular',
'ui.router',
'templates',
'ui.bootstrap',
'ng-token-auth'
]).config(authConfig);
authConfig.$inject = ['$authProvider'];
/** #ngInject */
function authConfig($authProvider) {
$authProvider.configure({
apiUrl: 'http://localhost:8000/'
});
}
})();
UPDATE
It seems that it either cannot find my config or getConfig does not exist:
addScopeMethods: function() {
return c.user = this.user,
c.authenticate = angular.bind(this, this.authenticate),
c.signOut = angular.bind(this, this.signOut),
c.destroyAccount = angular.bind(this, this.destroyAccount),
c.submitRegistration = angular.bind(this, this.submitRegistration),
c.submitLogin = angular.bind(this, this.submitLogin),
c.requestPasswordReset = angular.bind(this, this.requestPasswordReset),
c.updatePassword = angular.bind(this, this.updatePassword),
c.updateAccount = angular.bind(this, this.updateAccount),
this.getConfig().validateOnPageLoad ? this.validateUser({
config: this.getSavedConfig()
}) : void 0
},
It fails in the above code on this.getConfig().validateOnPageLoad because getConfig() is undefined. getSavedConfig() returns the expected config, however...
I'm using devise on the back end, so my understanding is that I just need a minimal config like this to get started.
Please let me know what other info I can provide!
I figured it out!
I changed my config to:
function authConfig($authProvider) {
$authProvider.configure([{
default: {
apiUrl: 'http://localhost:8000/'
},
user: {
apiUrl: 'http://localhost:8000/'
}
}]);
}
in getConfig e was undefined, so return t[this.getCurrentConfigName(e)] was returning 'user', but I had no config named 'user', so 'undefined' was returned. Adding a named config fixed this issue since t here is an object with keys that are the names of your config values.

Calling a javascript function, which is passed as a parameter from a javascript library

I'm currently trying to implement the fullcalendar javascript library into an angular 2 dart webapp.
I'm having problems porting this javascript code to dart though:
$('#fullCalendar').fullCalendar(
{
events: function(start, end, timezone, callback) {
var generated_events=[
{
title : 'test',
start : '2016-08-08'
}];
callback(generated_events);
},
allDaySlot: false
//More options can go here
});
I've gotten as far as being able to pass a dart function to the events parameter with this code:
context.callMethod(r'$',['#fullCalendar'])
.callMethod('fullCalendar',[new JsObject.jsify({
'events': (start, end, timezone, callback){
print("called!");
List<FullCalendarEvent> generated_events= [
new FullCalendarEvent(title: "test", start: "2016-08-08")
];
try{
callback(generated_events);
}catch(exception,stackTrace){
print("Caught exception!");
print(exception);
print(stackTrace);
}
},
'allDaySlot': false
//more options can go here
})]);
Where the FullCalendarEvent is a simple anoymous class structure:
#JS()
#anonymous
class FullCalendarEvent{
external String get title;
external set title(String v);
external String get start;
external set start(String v);
external factory FullCalendarEvent({
String title,
String start
});
}
However the callback(generated_events); throws this exception:
NoSuchMethodError: method not found: 'call$1' (callback.call$1 is not a function)
Edit:
With the help of Günter's replies I managed to fix the problem. Instead of doing callback(generated_events); I instead use callback.apply([generated_events]); Additionally instead of using
List<FullCalendarEvent> generated_events= [
new FullCalendarEvent(title: "test", start: "2016-08-08")
];
I instead use:
var generated_events = new JsObject.jsify([{'title':'test','start':'2016-08-08'}]);
My working code looks like this:
context.callMethod(r'$',['#fullCalendar'])
.callMethod('fullCalendar',[new JsObject.jsify({
'events': (start, end, timezone, callback){
print("called!");
var generated_events = new JsObject.jsify([{'title':'test','start':'2016-08-08'}]);
try{
callback.apply([generated_events]);
}catch(exception,stackTrace){
print("Caught exception!");
print(exception);
print(stackTrace);
}
},
'allDaySlot': false
//more options can go here
})]);
A JS function should be callable with
callback.apply([gen‌​erated_events])

Console logging certain objects don't work when developing a Firefox extension using React

Console logging certain objects, like this.refs or the window object results in a TypeError: cyclic object value error in the terminal.
My code is pretty basic: I'm trying to change the html on a web page (placing a react component in it).
Main.js:
var pageMod = require("sdk/page-mod");
var self = require("sdk/self");
var { MatchPattern } = require("sdk/util/match-pattern");
// Create a page mod
// It will run a script whenever a ".org" URL is loaded
// The script replaces the page contents with a message
pageMod.PageMod({
include: /.*wikipedia.org\/wiki\/.*/,
contentScriptFile: [
self.data.url("react-with-addons.js"),
self.data.url("testing.js"),
],
contentScriptWhen: "ready",
// contentStyleFile: self.data.url("style.css"),
});
testing.js:
var AppContainer = React.createClass({displayName: "AppContainer",
componentDidMount: function() {
console.log(this.refs.myRef);
console.log(window);
},
render: function() {
console.log('rendering');
return (
React.createElement("div", {ref: "myRef"})
);
}
});
React.render(React.createElement(AppContainer, null), document.getElementById('content'));
After running cfx run, the logs in the componentDidMount do not display anything in the browser console, and the cyclic object value displays (tried to log the window object to the console). Why is it having difficulties?

Trying to use jqplot with jquery mobile, marionette and requirejs

I am trying to use jqplot with Jquery mobile, marionette and requirejs. I have included all jqplot required CSS as well as script files in head tags, but when i am trying to plot a chart using below code
define([ 'jquery', 'plot' ],
function($) {
console.log("Success..Inside Offer Page Script.");
console.log("Plot..."+$.jqplot);
console.log("jquery..."+$);
$.jqplot.config.enablePlugins = true;
var s1 = [ 2, 6, 7, 10 ];
var ticks = [ 'a', 'b', 'c', 'd' ];
plot1 = $.jqplot('chart1', [ s1 ], {
seriesDefaults : {
renderer : $.jqplot.BarRenderer,
pointLabels : {
show : true
}
},
axes : {
xaxis : {
renderer : $.jqplot.CategoryAxisRenderer,
ticks : ticks
}
},
highlighter : {
show : false
}
});
});
it gives me errors like
Uncaught TypeError: undefined is not a function jqplot.barRenderer.js:41
(line 41: $.jqplot.BarRenderer.prototype = new $.jqplot.LineRenderer();)
Uncaught TypeError: Cannot call method 'push' of undefined jqplot.pointLabels.js:377
(line 377: $.jqplot.postSeriesInitHooks.push($.jqplot.PointLabels.init);)
The plot in my above code's define is
define([
'../scripts/ext_libs/jquery.jqplot'
],
function () {
var plot;
require([
'../scripts/ext_libs/jqplot.barRenderer',
'../scripts/ext_libs/jqplot.pointLabels',
'../scripts/ext_libs/jqplot.categoryAxisRenderer',
],
function () {
plot = $.jqplot;
});
return plot;
});
Can anyone please help me how can i solve these errors. Is their a problem using jqplot with requirejs?
Thanks in advance.
I'm not using marionette, but everything else works fine on my side. I have a jqplot module like this:
define([
'../js/plugins/jqplot/jquery.jqplot'
, 'css!../js/plugins/jqplot/jquery.jqplot'
],
function () {
var plot;
require([
'../js/plugins/jqplot/plugins/jqplot.barRenderer'
, '../js/plugins/jqplot/plugins/jqplot.logAxisRenderer'
, '../js/plugins/jqplot/plugins/jqplot.categoryAxisRenderer'
, '../js/plugins/jqplot/plugins/jqplot.canvasAxisTickRenderer'
, '../js/plugins/jqplot/plugins/jqplot.canvasTextRenderer'
, '../js/plugins/jqplot/plugins/jqplot.pointLabels'
, '../js/plugins/jqplot/plugins/jqplot.enhancedLegendRenderer'
],
function () {
plot = $.jqplot;
});
return plot;
}
);
which I'm requiring requiring normally from my page script like this:
require(["plot"], function (plot) {
// do something here with plot or... $.jqplot
};
You should be able to use $.plot right away, because once you require the module, jqplot will be available on $.
EDIT:
Try this:
define([ 'jquery', 'plot' ],
function($) {
console.log("Success..Inside Offer Page Script.");
console.log($);
console.log($.jqplot);
$.jqplot.config.enablePlugins = true;
var s1 = [ 2, 6, 7, 10 ];
var ticks = [ 'a', 'b', 'c', 'd' ];
plot1 = $.jqplot('chart1', [ s1 ], {
seriesDefaults : {
renderer : $.jqplot.BarRenderer,
pointLabels : {
show : true
}
},
axes : {
xaxis : {
renderer : $.jqplot.CategoryAxisRenderer,
ticks : ticks
}
},
highlighter : {
show : false
}
});
});
Bit late to the game but.... above doesn't work because require is async to return, so able to return jqplot without any jqplot plugins loaded! async safe solution below
Nasty problem, as it's a chain of three dependencies
jquery is required for jqplot which is required for jqplot plugins, I have a simpler solution based on the same lines as the one above
first do your requirejs "main.js" config like so
requirejs.config({
paths: {
"jquery": "path/to/jquery-1.10.2.min",
// WORKAROUND : jQuery plugins + shims
"jqplot.core": "path/to/jquery-jqplot-1.0.8.min",
"jqplot": "jquery-jqplot-module-with-plugins-1.0.8"
},
shim: {
"jqplot.core": {deps: ["jquery"]},
"jqplot": {deps: ["jqplot.core"]}
}
});
create a wrapper file module file called "jquery-jqplot-module-with-plugins-1.0.8.js", containing :
// wraps jquery jqplot plugin in define statement
define([
"jquery",
"path/to/jqplot.highlighter.min",
"path/to/jqplot.cursor.min",
"path/to/jqplot.dateAxisRenderer.min",
"path/to/jqplot.canvasTextRenderer.min",
"path/to/jqplot.canvasAxisLabelRenderer.min",
"path/to/jqplot.enhancedLegendRenderer.min",
"path/to/jqplot.pieRenderer.min",
"path/to/jqplot.donutRenderer.min",
], function($) {
var jqplot;
jqplot = $.jqplot;
return jqplot;
});
Then when ever you need jqplot with those plugins, simply call for "jqplot" which will load "jquery" then "jqplot.core" then all the jqplot modules, then finally return the jqplot object :)
require(["jquery", "jqplot"], function ($, $jqplot) {
console.log("Success..Inside Require JS");
console.log("Plot...", $.jqplot, $jqplot);
});
or
define(["jquery", "jqplot"], function ($, $jqplot) {
console.log("Success..Inside Define JS");
console.log("Plot...", $.jqplot, $jqplot);
});
tada! :)
ps jquery plugins are evil, no suggestion how to fix that situation, just a statement of fact
cheers
Ant
Looks like plot is returned before require(...) initializes it. I used to have common solution and my plot was partly populated. I ended up with setting all jqplot plugins in shim and changed my `plot.js' accordingly, as was suggested here.
requirejs.config
shim: {
'jqplot': ['jquery'],
'lib/jquery/jqplot/plugins/jqplot.canvasTextRenderer': ['jqplot'],
'lib/jquery/jqplot/plugins/jqplot.pieRenderer': ['jqplot'],
'lib/jquery/jqplot/plugins/jqplot.barRenderer': ['jqplot'],
'lib/jquery/jqplot/plugins/jqplot.categoryAxisRenderer': ['jqplot'],
'lib/jquery/jqplot/plugins/jqplot.canvasAxisLabelRenderer': ['jqplot'],
'lib/jquery/jqplot/plugins/jqplot.enhancedLegendRenderer': ['jqplot'],
'lib/jquery/jqplot/plugins/jqplot.highlighter': ['jqplot'],
}
plot.js
define(['lib/jquery/jqplot/plugins/jqplot.canvasTextRenderer',
'lib/jquery/jqplot/plugins/jqplot.pieRenderer',
'lib/jquery/jqplot/plugins/jqplot.barRenderer',
'lib/jquery/jqplot/plugins/jqplot.categoryAxisRenderer',
'lib/jquery/jqplot/plugins/jqplot.canvasAxisLabelRenderer',
'lib/jquery/jqplot/plugins/jqplot.enhancedLegendRenderer',
'lib/jquery/jqplot/plugins/jqplot.highlighter'],
function() {
return $.jqplot;
});

Resources