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.
Related
I'm writing an app with the electron-react-boilerplate framework.
I've been following a tutorial here: https://riptutorial.com/electron/example/19713/synchronous-ipc-communication
In my renderer process I have:
let a = window.electron.ipcRenderer.sendSync('LIST', []);
console.log(a);
and in my main process:
ipcMain.on('LIST', (event) => {
event.returnValue = 'test';
});
However the value 'a' is undefined when it is logged. What am I doing wrong?
I realised what I did wrong.
In preload.ts I exposed the function sendSync like below:
sendSync(channel: Channels, args: unknown[]) {
ipcRenderer.sendSync(channel, args);
},
...this didn't return anything, hence the undefined. I should have done:
sendSync(channel: Channels, args: unknown[]) {
return ipcRenderer.sendSync(channel, args);
},
Now it returns as expected!
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)
}
}
);
}
When trying to use validation in a global validator with this code:
errors.fieldMissing = [translate('aor.validation.fieldMissing')];
I get the following error:
Warning: Failed prop type: Invalid prop `errorText` supplied to `TextField`, expected a ReactNode.
Without the translation(), just setting the error to an array of a string, everything works as expected.
How can translation() be used in global validation?
For example(edited from AOR example posts):
<SimpleForm defaultValue={{ average_note: 0 }} validate={(values, props) => {
const errors = {};
['title', 'teaser'].forEach((field) => {
if (!values[field]) {
errors[field] = [props.translate('aor.validation.required')];
}
});
...
A short example of translate hoc and translate props:
import { translate as translator } from 'admin-on-rest';
const Title = translator(({ record, translate }) => <span>{record ? translate('title.product', { name: record.name }) : ''}</span>);
I do not understand why the following test is failing with the error:
TypeError: (intermediate value).should.be.type is not a function
describe('#Option object', function() {
it('returns value as whatever type was passed to the constructor', function() {
var o = function() {
this.getValue = function() {
return new Date();
}
};
var i = new o();
i.getValue().should.be.type('Date');
})
});
I've read [most] of the Should.js documentation but I must be missing something. Can anyone tell me what is wrong with my test?
Actually only one thing wrong. You read not should.js docs, but unit.js docs - it is not related to should.js at all.
Correct link.
Correct code will be:
i.getValue().should.be.instanceOf(Date);
or
i.getValue().should.be.Date();
I'm looking for an approach to reduce code duplication. Currently, whenever I save a Backbone model, I always provide the following code to deserialize the Rails stock 422 response into an errors property:
model.save({ name: "..." }, error: function(model, response) {
result = $.parseJSON(response.responseText)
model.errors = result.errors
...
});
Is it possible to configure Backbone so it deserializes errors before calling my callback? I tried overriding the sync method but at that point the callback is wrapped in a anonymous function (and no longer accessible).
You can use a ErrorHandler model that is extended by other models requiring error parsing. The ErrorHandler model should listen for the "error" event (triggered by the sync function when errors occur after a request).
var ErrorHandler = Backbone.Model.extend({
initialize: function() {
this.on("error", this.defaultErrorHandler, this);
},
defaultErrorHandler: function(model, error) {
result = $.parseJSON(response.responseText)
model.errors = result.errors
...
}
});
var OtherModel = ErrorHandler.extend({
...
});
var model = new OtherModel();
model.save({ name: "..." });