AngularJS routing parameters - javascript

friendID = 1234;
$route.when(
"/friends/:friendID/raw",
{
event: "friends.view"
}
);
When I run the above the URL in Chrome Dev Tools shows that the url tried is http://domain.com/friends/raw?0=1&1=2&2=3&3=4
is there a way to actually get it to run as http://domain.com/friends/1234/raw

It's difficult to tell what's going on here with only this snippet. Can you post the values of your JSON object? At first glance, it appears that your object it's passing multiple values. You might try setting its value to 1234 and see if it passes correctly.

Related

JS chrome console array not expanding

When I print an array, it shows up as a 100 element array of objects, but when I expand it, it doesn't expand. Instead, there is a blue info icon that says "Value below was evaluated just now", and the arrow changes direction. The problem is still there even if I clone my array when printing (which was an answer in another SO question).
I am actually using node.js with chrome debugger but I think the issue is the same. Here is my code
const axios = require('axios');
axios.get("https://--------")
.then(function(response) {
let data = response.data;
console.log(data.slice(0, 100));
});
axios just sends http requests.
I've read:
Is Chrome's JavaScript console lazy about evaluating arrays?
Weird behavior with objects & console.log
Your problem might be occurring because you are trying to expand the data structure after the debug session has ended.
Try add a debugger; after your console log to ensure you are expanding that array during your debug session.

Setting window.location in JavaScript hangs

I have an ASP.NET MVC app. My app uses jQuery on the client side. The user can enter values into several fields and click "Refresh". The Refresh is behaving oddly.
When Refresh is clicked, I execute the following JavaScript:
function refresh() {
var chosen = "(someField eq 'value')";
try {
if (chosen) {
var url = 'http://localhost:8089/item&c=' + chosen;
alert(url);
window.location = url;
} else {
window.location = 'http://localhost:8089/item';
}
return false;
} catch (ex1) {
alert(ex1);
}
}
The value for chosen is actually generated via a function. I've noticed when I use a certain type of control, the page hangs. Here is what is odd, I can see the request made in Fiddler. Yet, my breakpoint in my controller action is never hit. If I copy and paste the url from the alert call into the address bar, my breakpoint gets successfully hit. So, I'm totally confused.
Due to the fact this involves a specific control, I at first assumed this was a JavaScript error. However, I do not see any JavaScript error in the console. I also checked to see if any exceptions were being swallowed and I did not see any.
The fact I see the request in Fiddler, would imply that I'm getting to the web server. Yet, if I have a breakpoint on the very first line of the controller action, I would expected that to trip. It does not trip in the scenario where I use the control. It does trip if I do NOT use the control. The result in Fiddler sits at '-'. It never returns. Plus, I do not get an exception thrown in my ASP.NET view.
I'm totally stuck on this and looking for ideas of potential causes. Thank you.
This behavior is usually the result of a problem during model binding for the controller.
A quick step to try is making sure the query string values you are sending are properly encoded.
var chosen = "(someField eq 'value')";
chosen = encodeURIComponent(chosen);
Would eliminate any bad character problems that the model binder might be having.

WebdriverJS dump to terminal?

I am finding it very difficult to debug a test using WebDriverJs because I don't know how to see the value of a variable. For example, I am trying to access the window handle of a pop-up. I can test .toNotBe(null), but I would like to know the actual value. Every time I want to use it in the next logical step of driver.switchTo().window(handle) I get the error that NameOrHandle is not defined. That is probably the next question on SO; but for now I just want to know what node thinks "handle" is if not null but still not defined.
Is there a dump() command, or a helper library I can load into my spec with require that will allow me to dump an object's value to the terminal?
You should just be able to console.log() to dump your output to the terminal. For example:
driver.getAllWindowHandles().then(function(windows){
var originalWindow = windows[0];
var popupWindow = windows[1];
if (popupWindow) {
driver.switchTo().window(popupWindow);
driver.getTitle().then(function(popupTitle){
console.log("popupTitle is set to: ", popupTitle);
next();
});
}
});

Where should I start, models are there but... they aren't?

working with backbone, I was seeing a problem where some data was being left blank, so I wrote this to try to see what was going on.
console.log('actions.models', this.model.actions.models)
console.log('actions.models.length', this.model.actions.models.length)
console.log('first actions.models', this.model.actions.models[0])
the output
actions.models [ Action ]
actions.models.length 0
first actions.models undefined
if I add a setTimeout of say 2 seconds to this code I get
actions.models [ Action ]
actions.models.length 1
first actions.models Action
I don't get how this could happen. I don't know where to start looking or even what would be helpful to post for you guys to look at.
If anyone can help point me in the right direction I would appreciate it. Thanks very much.
Are you loading the models via an Ajax function, like fetch? If so, you can't count on data being loaded until the Ajax function's callback is invoked, e.g.
actions.fetch {success: -> console.log actions.models.length}
Not sure what you are trying to do, but anyway.. When you dump objects to the console log, be aware of the fact that since objects are passed by reference, whatever you get from inspecting it in the log will be whatever the object ended up being. Assuming you want to log the state of an object you should probably try to serialize it when logging. For instance console.log "mymodel: ", JSON.stringify(mymodel.attributes).
Also be aware that to access backbone models, you would typically use name = mymodel.get('name'), or for a collection item = mycollection.get('someid').
If you post some testable code and what you are trying to accomplish, I'm sure somebody with a clue will be able to help you out.

Client side routing. How does it work?

I need a client-side routing solution to work with a chrome app. I've researched several and crossroads.js seems like a good fit. When I include it in my html file, it doesn't seem to work; that is, if I use code like
crossroads.addRoute('/news/{id}', function(id){
alert(id);
});
crossroads.parse('/news/123');
, the page alerts '123' but if I type '/news/321' in the browser's url bar, it preforms the browser's default action, instead of alerting '321'. What am I doing wrong. (Also, I realize the title is broad, but I believe the difficulties I'm having with crossroads.js are more general than crossroads.js in particular. It is given as an example.)
Use Hasher (by the same author) also.
The documentation on the Crossroads page tells you that you need to use Hasher, (because that will be used for monitoring the widow.location bar.).
So you would also need to use Hasher, and initialise it, then you can add your "Crossroads" routes to Hasher to start monitoring for those particular routes.
//setup crossroads
crossroads.addRoute('foo');
crossroads.addRoute('lorem/ipsum');
crossroads.routed.add(console.log, console); //log all routes
//setup hasher
hasher.initialized.add(crossroads.parse, crossroads); //parse initial hash
hasher.changed.add(crossroads.parse, crossroads); //parse hash changes
hasher.init(); //start listening for history change
//update URL fragment generating new history record
hasher.setHash('lorem/ipsum');
http://millermedeiros.github.com/crossroads.js/
The command parse tells crossroads to have a look at the string and do an action based on it.
So in the case of crossroads.parse('/news/123'); it will always use /news/123.
Since you want crossroads to parse what you have in the browser address bar, you'll need to use that value in the parse method:
crossroads.parse(document.location.pathname);

Categories