Nothing happening when I click Post Comment button (ThinksterIO:Real Time Webapps tutorial) - angularjs

I ran into another snag while going through the ThinksterIO Learn to Build Real Time Webapps tutorial around the 90% mark where one is shown how to add and delete comments:
https://thinkster.io/angulartutorial/learn-to-build-realtime-webapps/#adding-comments-functionality-to-the-post-service-9
Every time I click the Post Comment button absolutely nothing happen and I simply can't figure it out. I am expecting some kind of error to show up but nil. It's as if the button is not hooked up to the function. I was so frustrated that I eventually just copy and pasted the code from the tutorial to make sure I had it down right. Even after doing that it still didn't work.
I've created a Plunker with this app running over here http://embed.plnkr.co/OhzDTU/preview
You can sign in with the email user#user.com and 1234 password. You will then be able to try to comment on posts. Any ideas on what is going wrong here?
UPDATE
I took away the user user#user.com and 1234 password since problem is now fixed.

Your add comment button is in showpost.html, which is rendered by PostViewCtrl. However, your addComment method is attached to the scope of PostsCtrl (it doesn't exist when you try to click it). The simplest answer here is just to move addComment() over to the other controller.
Regarding the lack of error messages, I don't think that you can get an error for this. I had a look at the docs for $log and tried to decide if you could add some debugging output, but it looks like it's already on (i.e. the lack of a method seems to fail silently).
About your only option here is to try something like {{addComment|json}} in the view to see if it exists, but you'd first have to suspect that it didn't.

Related

Not able to set list2 in Adobe Launch in custom code

I am trying to set list2 in my analytics call through custom code but it is not getting set.
This issue comes with s.tl() only while with s.t() method, it is triggered correctly.
Below is the code :-
s.addEvent("event12", true);
s.linkTrackVars = "list2";
s.list2 = "Data"
s.tl(this, "d", "Download", s);
If I place logger just before beacon call, it shows the value. However, when I click the button and check for same, only "event12" get fired and not "list2".
Any help would be highly appreciated.
Just tested your code on lululemon:
Conclusion:
You're overwriting either the listvar or the linkTrackVars somewhere else. As #Crayton Mentioned above, doPlugins would be a good spot for it.
But it actually can be overwritten anywhere. In any rule that fires prior, or the s code, or any DE affected.
Paste your code into the console. Execute. Do you see the listvar populated? If yes, then your problem is in rules, so check them. You're not supposed to reassign linktrackvars. Always use the s.apl() plugin.
If no, however, then your problem is definitely in doPlugins. Sometimes I have it when I have silent catches in s code. Pageviews would have all vars populated, but links would have mixed results. Check your error reporting in the catches in doPlugins. I suggest having all code in doPlugins in a try catch.

CheckBox.setToggleButton doesn't exist

i have been trying a code found here to add rating bar but i got an error on
cb.setToggleButton(
where the "setToggleButton" method didn't or doesn't exist anymore
any idea if it has been update cause the post i tagged was back from 2014
That method doesn't exist, it should be setToggle(true). Notice in the linked post it just said setToggleButton( without even a closing bracket. Since this was written a while back I'm guessing I just switched a desktop to check the method name and got distracted then forgot to fix that. Hazards of blind coding without the comfort of an IDE.
#devcrp actually wrote the correct answer before but unfortunately he deleted it. If he undeletes it his answer should be accepted.

How do i close div and reopen in reactjs

I am learning reactjs, and was making note taking app. Its working fine so far, but it isnt working when i close a note and then try to open same note again. If i open any other note than the one i closed it works fine.
I know that my if condition is causing this because i have below condition in my code nextProps.note.id !== this.state.note.id which only returns true if ids are different.
I tried many many variations but i am not able to implement note details and close feature all together. I know i am so close and just making some silly mistake, but i am not able to catch that mistake may be my reactjs understanding is weak.
If someone can point me in right direction or just give a clue that will be a great help, as i have spent many hours on this with no luck so far.
Demo : https://codesandbox.io/s/wqqklork
How to recreate bug : Click on note 1, then click close note button and then again click note 1 (this will not work), But if you click note 2 it will work.
I believe its an issue with component lifecycle,when you click a new note a whole new component is rendered but when you click on the same component twice,the second time a new component is not rendered but the same same one is updated. Check on the willcomponentupdate lifecycle method .Hope that helps.

React Component accidentally share state

Anyone know what is the problem? Each post is a component on its own. When I click the comment button of the second post, the comment box on the first post appear instead.
You code showing that you have written code for like and unlike a post in you Post component. The code is common for all posts. Try to create a separate component for like section.
See this SO for a similar example: React toggle like button
For those who might come across this thread later, I haven't found any valid solution by now. Thus, how I solve this is kinda a bit hacky and might cost a lot of time if your app is quite complex. I added id(not HTML id) to each post and loop through each post and check the id with the id of the element that emits the action to show comment box. If they match simply set the display of the comment box to block.

How do I find the context in which document.write operates. Can you solve the riddle

Basically i have these two lines of code written right after each other.:
console.log(typeof (noAdsCallback));
document.write('<sc' + 'ript type="text/javascript">console.log(typeof(noAdsCallback));</scr' + 'ipt>');
The first one logs function, the second logs undefined.
Of course it's a bit trickier than that. So here is the set-up in a nutshell:
I have a so called waterfall of ad-providers. That means, I try to load some Ads, by writing (using document.write) some special tags (given to me by my ad-provider).
If the provider doesn't find an ad for me, they send back a javascript-snippet which looks like this:
if (typeof(window.noAdsCallback) === "function") noAdsCallback();
This function essentially writes the tags of the next provider, which does the same as the first one until I reach the end of the list.
This system actually works fine, doing exactly what I want it to do. Both lines given in the beginning log function.
Except if I use Google as an ad-provider. There is one thing Google does differently, which seems to mess everything up.
In Google, I cannot define a fallback-JavaScript-snippet. All I can do is provide a fallback-url. So this fallback-url (since it's loaded inside an iframe inside an iframe inside...) sends a postMessage to the top, which then calls the same noAdsCallback() method. And this too, works just fine. The message is received and the right method executed. However, already the two lines already give different results, i.e. function and undefined respectively
The next provider then fails to find the noAdsCallback() Method, when it returns, because it uses document.write to try to execute it. Somehow, the context was lost.
First hint: It works fine (i.e. both lines log function) in Chrome, but it doesn't work in FF or IE.
Second hint: It works fine, as long as context never switches, but if communication runs at any point through messaging, it get's confused.
Third hint: Using the fantastic postscribe library as mentioned below, actually solves the problem, but introduces new ones somewhere else.
Fourth hint: Debugging the window.name, before using document.write, gives the correct name, so I'm not in a random iFrame.
Finishing thoughts. I know, i know: DON'T USE DOCUMENT WRITE!! I know that. But since Adproviders use it all the time, I am forced to use it to, otherwise I get this:
Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
In Fact, right now I'm using postscribe (https://github.com/krux/postscribe) and it works like a charm, except for one lousey provider. And the workauround solution would be, to use document.write only for this lousy provider and postscribe for all the others. But i would really like to find out what the root of the problem is.
Any Ideas, much appreciated.
I think I understood it now. Long story short: DON'T USE DOCUMENT.WRITE :)
Try postscribe, if you have to.
So in hindsight it is quite obvious, because really, anywhere you read about document.write() it says, that write() clears the whole document. And I just didn't get it, because I never saw it happening and every ad is using it, like the whole time. Plus, it seemed to work fine on Chrome. So what's going on??
Well here is what happens. As long as the document is open, which basically means while it is being written, document.write() just appends to the stream, and doesn't clear the document. And as long as I used document.write(), to append foreign ad-scripts (which may and will contain document.write()), the page does not close, hence the document stays open.
This is the reason, why adding Google to my waterfall, posed a problem: Google puts everything in iframes. So the page containing the waterfall model just sees the iframe and says: "well as far as I'm concerned, I'm done" and closes the document, while in fact, Google is still at it.
Afterwards, Google didn't find an ad, sends a postMessage to the main page, causing the next provider to be used. Who then uses document.write() and clears everything.
Everything? Not everything. Remember, it still used to work when I used Chrome? The reason for that is, Chrome just clears the HTML but leaves the Javascript intact. So on Chrome, my Javascript-waterfall worked fine, because all the JS-objects where still in place. All other browsers cleared it.
So that's it. Probably noone's gonna read it, but if you do, USE POSTSCRIBE! Now that I finally really understood document.write() and document.open() and document.close() I'm a big fan.

Resources