The JavaScript code in angularJS fails to execute properly after importing angular.js

As a newcomer to AngularJS, I'm puzzled by why the code below isn't functioning as expected. The browser is not loading the file 'myjavascriptcode.js'. When I place

"<script src="./myjavascriptcode.js"></script>"
before importing Angular, the 'myjavascriptcode' file loads but triggers an 'angular is not defined' exception. Surprisingly, the only workaround that seems to make it work is placing
"<script src="../../angular-1.5.8/angular.js"></script>"
before the HTML tag.

jsdemo.html

<!DOCTYPE html>
<html>
    <head>
       <title>To do</title>

       <script src="../../angular-1.2.5/angular.js" />  
       <script src="./myjavascriptcode.js"></script>

    </head>
    <body>
        This is a simple example
    </body>        
</html>

./myjavascriptcode.js

function printMessage(unknownObject){
    if( angular.isFunction(unknownObject) ){
        unknownObject();
    }else{
        console.log("mi hai passato una variabile not function");
    }
};

var variable1 = function sayHello(){
    console.log("Hello");
}

var variable2 = "GoodBye!";


printMessage(variable1);
printMessage(variable2);

    enter code here

Answer №1

The angular tag in your code is missing the closing bracket, which is causing the javascript not to load properly.

 <script src="../../angular-1.2.5/angular.js"></script>  
 <script src="./myjavascriptcode.js"></script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring the use of jQuery/JS for parsing and working with JSON

Hi everyone, I need some assistance with displaying data from an array created by a PHP file using JS/jQuery. Currently, I am working on implementing a points system for ZetaBoards which you can check out here. The points will be shown below the user' ...

Unable to store the data retrieved from MySQL into an array

Every time I try to add the object result1 to the array a, it ends up empty. Can someone help me figure out what I'm doing wrong? app.get('/freezer', (req, res) => { var a = []; var sql = `SELECT freezer_id FROM freezer_data`; ...

The $.ajax request encounters an error when trying to parse the data as JSON

I am encountering an issue where my ajax call to a JSON file fails when using dataType: "json". However, changing it to "text" allows the ajax call to succeed. See the code snippet below: $.ajax({ type: "POST", url: url, dataType: "json", ...

Creating a Javascript function to turn lights off using CSS manipulation, similar to the feature found

Is there a way to use JavaScript to obscure all elements on a page except for one specific HTML element? This web application is optimized for Chrome, so CSS3 can also be utilized. ...

Compatibility problem arising from the versions of ember-precompile, ember.js, and handlebars.js

Having trouble reading the precompiled templates in my HTML due to compatibility issues between ember-precompile, ember.js, and handlebars.js. My code looks like this: Includes the following files. <script src="../js/libs/jquery-1.10.2.js"></sc ...

Trigger an AJAX request to execute a PHP script when a button is clicked

When I click a button, I want to run an ajax function that calls a PHP script and displays the resulting data under a specific div. However, it is not currently working as expected. Upon checking the console, I noticed that no value is being passed to the ...

The oddity of a lone quotation mark trying to break

var x = "Test \'" > undefined var y = "Test '" > undefined x === y > true x > "Test '" https://i.stack.imgur.com/ZrHo5.jpg Aha! Both of these strings are actually equal (as shown in the example code) - but why is that the ...

How can I swap out the text within an anchor tag using jQuery?

I am working with the following HTML structure: <div class="event tiny"> <a href="/whatever">Something</a> </div> My goal is to change the text of this link to "Anything" … However, when I try the following code: $('. ...

Using AngularJS to fetch images from RSS feed description

I'm currently learning AngularJS by creating a simple RSS feed. I have successfully made a JSON request and fetched all the data including title, link, description, and images from the RSS feed I parsed. The code snippet for extracting images looks li ...

Angular2's $compile directive functions similarly to AngularJS 1's $compile directive

I am currently in the process of migrating my project from Angular 1 to Angular 2 and I am in need of a compile directive. However, I am struggling to rewrite it to achieve the same functionality as before. app.directive("compile", compile); compile.$inje ...

Utilize the onChangeText function in React Native to filter out each individual value within a nested array

I currently have an array with nested children in it, where the children can range from one to multiple values. I am working on implementing a local filter within my component. Whenever a user types anything into the textInput, the application will display ...

What is the best method for incorporating two materials into a mesh that has already been rendered on the canvas?

I've been experimenting with adding both color and an image to a Three.js Mesh after it's already been rendered on the canvas. From what I understand, if I use the same material with both color and a map, they will blend together and there's ...

The AJAX function failed to trigger another JavaScript function after successfully completing its task

Trying to figure out how to execute a function after successful AJAX post request. The function I want to call is: function col() { var $container = $(".post-users-body"); $container.imagesLoaded(function() { $container.masonr ...

Discover the power of AngularJS's ng-route feature for creating a dynamic and seamless one-page HTML template experience

I'm attempting to create a dynamic header using ng-repeat. Here's the initial code: <ul class="right"> <li><a href="#carousel">Home</a></li> <li><a href="#about-us">About Us</a></li> &l ...

$http.get is successful, but unfortunately, $http.post is not functioning properly

Hey there! I'm facing a little issue with my code that involves fetching data from an external file using $http.get. It works perfectly fine for me, but when I switch to $http.post, I encounter a "syntaxerror: unexpected token < at object.parse(nat ...

Converting jQuery selectors into JSON objects

I would like to create a JSON object from a jQuery selector string, which is the text inside $(), without actually selecting elements from the DOM. Is there a built-in function in jQuery that can achieve this task or are there any open-source libraries ava ...

There seems to be a mistake in the code: `return item.name.contains('$scope.inputQuery');`

The html(jade) includes: body(ng-controller='myAppController') <input ng-model="inputQuery"> ul li(ng-repeat="phone in phones|filter:query") {{phone.name}} p {{phone.snippet}} The controller is defined as: f ...

Mark scheduled specific time periods

I need help removing booked time slots from the total time slots. How can I achieve this? Input: Actual time slots: [ '10:00-10:30', '10:30-11:00', '11:00-11:30', '11:30-12:00', '12:00-12:30', ...

What is the secret to creating a button that can sort text and another button that flips the word density in my content?

I'm not a fan of having something like this because it's displeasing to the eye: https://i.stack.imgur.com/3F4sp.jpg Instead, I prefer my word density to be more organized and structured. How can I achieve this? Sort by highest word density fi ...

Typescript counterpart of a collection of key-value pairs with string keys and string values

Within the API I'm currently working with, the response utilizes a data type of List<KeyValuePair<string, string>> in C#. The structure appears as shown below: "MetaData": [ { "key": "Name", &q ...