Angular JS Troubleshooting: Application Not Functioning Properly

I've been learning AngularJS on codeSchool and I ran into an issue with my simple hello world app. It was working fine at first but then stopped completely. I can't seem to find the bug, so any help would be appreciated. Here is the HTML code:

<!DOCTYPE html>
<html ng-app="store">
<head>
    <title>Angular Code School</title>
    <link rel="stylesheet" href="bootstrap.min.css">
</head>
<body>
    <script type="text/javascript" src="angular.js"></script>
    <script type="text/javascript" src="app.js"></script>
    I am {{4+6}}
    {{"Hello +"World"}}
<div ng-controller="StoreCtrl as store">
<div ng-repeat="product in store.products| orderBy:'-price'">
<h2>Name :{{product.name}} </h2>

    <h2>Price:{{product.price | currency}} </h2>
    <h2>Description:{{product.description}} </h2>
    <button ng-show="product.canPurchase">Add To Cart </button>

<section ng-controller="PanelCtrl as panel">
    <ul class="nav nav-pills">
        <li ng-class="{'active':panel.isSelectedTab(1)}"><a href ng-click="panel.selectTab(1)"> Description</a></li>
        <li ng-class="{'active':panel.isSelectedTab(2)}"><a href ng-click="panel.selectTab(2)">Specs</a></li>
        <li ng-class="{'active':panel.isSelectedTab(3)}"><a href ng-click="panel.selectTab(3)">Reviews</a></li>
    </ul>
    <div ng-show="panel.isSelectedTab(1)">This is description div</div>
    <div ng-show="panel.isSelectedTab(2)">This is Specification Section</div>
    <div ng-show="panel.isSelectedTab(3)">This is Reviews section</div>
</section>
</div>
</div>


</body>
</html>

appTest.js

var app = angular.module('store', []);

app.controller('StoreCtrl', ['$scope', function ($scope) {
    this.products = gems;
}])

gems = [{
    name: 'Dodecahedron',
    price: 2.95,
    description: 'This is the description of Dodecahedron'
    canPurchase: false;
},
{
    name:'Diamond',
    price: 5.95,
    description: 'Diamond is the most luxuriest gem of all.'
    canPurchase:true;
}]

app.controller('PanelCtrl', ['$scope', function ($scope) {
    this.tab=1;
    this.selectTab = function(setTab) {
        this.tab = setTab;
    };
    this.isSelectedTab = function(checkTab){
        return this.tab===checkTab;
    }

}])

The layout of my directory looks like this

root/
   angular.js
   appTest.js
   index.html

Here is a screenshot of the page with console https://i.sstatic.net/2Jdhc.png

Answer №1

mainApp.js

var mainApp = angular.module('shop', []);

mainApp.controller('ShopCtrl', function() {
    this.items = products;
});

mainApp.controller('TabCtrl', function() {
    this.tabIndex = 1;

    this.selectTabIndex = function(setIndex) {
        this.tabIndex = setIndex;
    };

    this.isIndexSelected = function(checkIndex) {
        return this.tabIndex === checkIndex;
    };
});

var products = 
    [{
        name: 'Ruby',
        price: 10.99,
        description: 'A beautiful red gemstone known as Ruby.',
        canPurchase: true
    },
    {
        name: 'Sapphire',
        price: 8.75,
        description: 'Sapphire is a blue gem with a touch of elegance.',
        canPurchase: true
    }];

also in app.html {{"Goodbye" +"World"}} should be {{"Goodbye" + "World"}}

Answer №2

You seem to be missing a double quote:

{{"Hello +"World"}}

it should actually be:

{{"Hello " + "World"}}

Please review your console for any javascript errors.

Answer №3

Here are three issues that need attention:

  • Update the greeting words in the following way

    {{ "Hello" + "World"}}

within your appTest.js file,

  • Add a comma after the description fields of the 'gem'
  • Remove the ";" semicolon after "canPurchase"

In your HTML file

  • Make sure to include "appTest.js" and not just "app.js"

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

What methods are most effective for designing a static side panel featuring a personalized tree-style list?

I am currently working on a sidebar design which is not rendering correctly, displaying a lot of flicker when expanded. I opted for b-nav instead of a traditional sidebar due to the interference it caused with my horizontal navigation bar. Here are my code ...

Unexpected behavior observed in the Python minifier Slimit

Attempting to decrease the size of some JavaScript code using the 'slimit' package in Python. import slimit slimit.minify('[1,2,3,4,5,6,7,8]') The above snippet executes without issue and outputs '[1,2,3,4,5,6,7,8]' import ...

An analysis of Universal Angular.io and Prerender.io from the viewpoint of Googlebot

Currently, my website is set up with Angular 1.4.x and prerender.io, which delivers static cached pages to Googlebot. Googlebot visits each page twice - once by hitting the URL directly, and then again by appending ?_escaped_fragment_ to the URL to access ...

How is it possible that my form is able to save data into the database even without any

I am considering adding a captcha process to my form and I am brainstorming some logic for it. I downloaded a login from Google, but I am confused why my form is still storing data into the database using action=' ' instead of action="register.ph ...

What methods can I use to generate unique paths within a URL for a website, and how can I assign a distinct status to each path?

I have developed a JavaScript program that allows you to draw using canvas. I have now set up a web server with Node.js in order to enable drawing on the website. Each specific drawing will be saved as a unique URL path so that you can resume where you lef ...

All browsers experiencing issues with autoplay audio function

While creating an HTML page, I decided to include an audio element in the header using the code below: <audio id="audio_play"> <source src="voice/Story 2_A.m4a" type="audio/ogg" /> </audio> <img class= ...

Scale the cylinder in Three.js from a specific point

Can a cylinder be resized along the Y-axis starting from a particular point? Instead of the cylinder expanding from its center in both directions to the new scale, is it possible for it to grow upwards/downwards only like a bar chart? Current code : fu ...

When accessing a page from a link, JavaScript sometimes does not immediately execute on the first attempt

I'm encountering a strange issue in my rails application, where a template fails to execute the Javascript code the first time it is loaded via a link on my home page. This problem only occurs when accessed through the link for the first time. I' ...

Is it possible to showcase a previously stored image from MongoDB using AngularJS?

After successfully saving images in MongoDB using AngularJS and Java, I now face the challenge of retrieving the saved image from MongoDB and displaying it on an HTML page using AngularJS. Just to clarify, I am familiar with ngSrc for handling image sourc ...

Discovering the active controllers in current AngularJS implementation

Is there a method to obtain a current list of active controllers? I have an object within my factory and a controller named "myController". Thus, I want to set myFactory.object={} (empty this object) if the myController is no longer connected to the modu ...

Recent npm dependency error found in local development setup after functioning properly

Today, I have been diligently working on a local project and a local npm package that is being used in the project. Everything was running smoothly up until now - my project and the library were functioning without any issues when installed with npm instal ...

Is there a way to verify the selection of all mandatory fields prior to concealing a div?

var count = 2; $('.next').click(function() { var requiredField = true; $(this).siblings('table').find('tbody tr:nth-child(' + count + ') td').each(function() { var element = $(this).find('center').f ...

Unable to locate module: Unable to locate the file './Header.module.scss' in '/vercel/path0/components/Header'

I encountered an error while attempting to deploy my next application on Vercel. I have thoroughly reviewed my imports, but I am unable to pinpoint the issue. Module not found: Can't resolve './Header.module.scss' in '/vercel/path0/comp ...

Retrieve items from an array using a series of nested map operations

When I execute the query below, it transforms the json data into objects - 1st level being a map (This works fine as expected) const customerOptions = () => { return customersQuery.edges.map(({ node: { id, name } }) => { return { key: id, text ...

Uploading files using Angular can result in a null HttpPostedFileBase

When working with Angular in conjunction with MVC, I am facing an issue where the HttpPostedFileBase is coming up as null when attempting to upload a file. This is how the HTML looks: <input type="file" data-ng-model="fileName" onchange="angular.eleme ...

Difficulty in toggling on and off several form elements with JavaScript

Trying to control multiple form elements on an HTML page with JavaScript has presented a challenge for me. In my form, each row contains a checkbox that should enable/disable the elements on that row. The issue I'm facing is that only the first two f ...

I want to use the enter key for posting, but also have the ability to use the shift and enter key to create a

$("#post_text").keydown(function(e){ // Checking if Enter key was pressed without shift key if (e.keyCode == 13) { // Prevent default behavior e.preventDefault(); } if (e.keyCode == 13 && !e.shiftKey) { alert('test'); } }); I a ...

Navigating through the year selection with your keyboard

By default, a dropdown menu containing years allows for keyboard navigation. For example, if you type in 1992 while the dropdown is selected, it will automatically move to that specific year option. I am curious to know if there is a way to activate a two ...

Tips for simulating a service in Angular unit tests?

My current service subscription is making a promise: getTaskData = async() { line 1 let response = this.getTaskSV.getTaskData().toPromise(); line 2 this.loading = false; } I attempted the following approach: it('should load getTaskData', ...

Creating dynamic variable names in Jquery by combining strings and numbers

Hey there, I'm really stuck and in need of a solution for the issue I've encountered. Currently, I have a script that sends an Ajax GET request and retrieves JSON data. The data is successfully returned, but when I try to loop through it, that&a ...