I'm very new to angular 2, so I'm trying to make this work: https://angular.io/guide/quickstart
The problem which I have really confuses me. All JS files, which I get as a response, have strange encoding - basically, I see a bunch of hieroglyphs. Non-js files (html and css) are ok. Please see below, html is ok. Js - totally not.
Do you guys have any idea, what can it be? Computer culture is not Chinese or Japanese, just in case.
You can use notepad++ or any html editor with encode options available to change the page encoding:
Open your file with Notepad++
Go to "Encoding" menu option in main menu
Select "Convert to UTF-8-BOM"
check if the page display correctly
This can be related to your js files encoding on your editor.
Related
I am trying to run a script through HTML but I am having some problems. I searched online and found how to do so, however the issue is that even if I correctly type the path of the .js file, it seems to add some strange characters before it.
This is in index.html
<script type="text/javascript" src="fractalTest/fractalTest.js"></script>
I expected this to work but when I open index.html in google chrome and inspect then look under the elements tab, this "â©fractalTest/fractalTest.js" is replacing "fractalTest/fractalTest.js" in the path of the file. I believe this is whats causing the error but I do not know how to fix it!
...it seems to add some strange characters before it.
That usually means that the file is saved with a byte-order mark (BOM) of some kind, but isn't being sent with the correct charset for that byte-order mark.
Be sure that the server is configured to serve the files with a specific encoding (UTF-8 is a good choice), and that you save the files using that encoding (in your text editor, etc.). It's also usually best not to include a BOM on UTF-8 files (although it's valid, some tools don't handle it well).
Side note: No need for the type attribute. The default is JavaScript.
I'm using the Angular Dialog Service to build pop up forms on my website. This services source can be found here: https://github.com/m-e-conroy/angular-dialog-service/blob/master/README.md
Anyway, the actual angular and JavaScript that describes what the modal contains and does goes after the following where the ... is:
.run(['$templateCache',function($templateCache){
$templateCache.put(...)
My problem is the html and js seem to have to all be one after the other with no spacing or indentation allowed between any of it. This causes the code that describes the modal to essentially just be a wall of text that has become borderline unreadable and editable in my complicated modal. An example of this can be found in the JS portion of the code here: http://codepen.io/m-e-conroy/pen/rkIqv
Is there an easy fix which will allow me to have my modals html and JS in non wall of text format and have it build successfully? If there is no fix this seems like a pretty big flaw in using the Angular Dialog Service to handle modals...
Thanks!
There are tools, like html2js, that can build templateCache for you.
It means, that you can store your html code in html files (where it obviously should be), and then gather it into single javascript file with $templateCache.put(/* content of html file */); in it. Just don't forget to include resulting module into your project, so when one of the services requested html file, it could be found in templateCache.
So you shouldn't edit html in .js files. It's wrong on many levels.
I'm using Notepad++ to do Javascript, and it doesn't work. This is what comes out in the web page:
, not the actual thing it would display when it runs properly.
I have the notepad++ 6.6.7 version.
Here's how I did it:
Write the code.
Change the language to Javascript.
Run it in Google Chrome.
And this is my result!?!?:
Am I not using Notepad++ correctly or my code has an error in it? Thank you so much!
Rename your file to somefilename.html.
You're saving your file as thing.txt. Save it as thing.html.
Also you're saying that you are working on javascript, but your code only contains html, so even you try to choose the language as javascript, javascript format won't work (but first save it as html file).
Browsers will render HTML and execute JavaScript in HTML documents not text documents as your filename of thing.txt suggests.
If you're experimenting try one of these sites: http://jsbin.com/ or http://jsfiddle.net/
I have some twig files that are a mixture of JavaScript, HTML, and twig markup. Is there a way with Eclipse to hi-lite a section of code and format it as, say JavaScript, then hi-lite another section and format it as HTML? I tried association the file type *.twig with the JavaScript editor, but, I do not seem to get any formatting. Syntax highlighting and code completion would be good too.
Thanks,
Scott
It is possible. If you have HTML/JS editors available (eclipse classic has them by default).
Go to preferences and: General > Editors > File Associations and add *.twig as a new file type and then add HTML editor (in the bottom panel) to it.
Then go to: General > Content Types, click on Text/HTML node (in Content Types box) and add *.twig file association in the bottom panel.
I've checked this and it works.
You can try to find a plugin that will support twig files and provide syntax highlighting. The Twig Eclipse Plugin looks promising as it at least seems to support HTML and twig markup together.
I've just installed nXhtml by downloading their zip file, extracting the archive into my home directory and adding (load "/home/spinlock/nxhtml/autostart.el") to my .emacs file. My problem is that when I try to edit a .js.erb file, I'm getting the error:
(No javascript-mode/eruby-javascript)
and I'm not getting the syntax highlighting that I'd expect (for instance, comments are the same color as javascript code). However, when I move the cursor inside a Ruby section of this file, that notice changes to:
(Ruby/eruby-javascript)
which I take as a good sign plus it does look like I've got the proper Ruby syntax highlighting in this part of the buffer (e.g. comments are show in red font).
I assume that I need to add a configuration file that tells emacs how to manage javascript-mode but I have no clue how to do this. Any help would be greatly appreciated.
Thanks!