Plunker fails to run simple AngularJS demo

I'm having trouble figuring out why this basic example isn't functioning as expected on Plunker.

http://plnkr.co/edit/EfNxzzQhAb8xAcFZGKm3?p=preview

var app = angular.module("App",[]);

var Controller = function($scope){

  $scope.message ="Hello";
};


app.contoller("Controller",['$scope',Controller]);


var app = angular.module("App",[]);

var Controller = function($scope){

  $scope.message ="Hello";
};


app.contoller("Controller",['$scope',Controller]);

Answer №1

Plunker provides a ready-to-use angular syntax to kickstart your project with industry best practices:

Take a look at this:

http://plnkr.co/edit/tpl:8rFfZljYNl3z1A4LKSL2?p=preview

<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8cede2ebf9e0edfea2e6ffccbda2b8a2f4">[email protected]</a>" src="https://code.angularjs.org/1.4.0-rc.2/angular.js" data-semver="1.4.0-rc.2"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
  </body>

</html>

JS:

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

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';
});

Answer №2

The word controller was mistakenly spelled as contoller.

Answer №3

Starting with the "Controller as" syntax is key to understanding AngularJS development. While you may come across examples using $scope, it's no longer the recommended approach for binding controllers to views. For more information, refer to AngularJS.org's documentation on ngController.

Check out this Plunker demo: http://plnkr.co/edit/aydvXaJNXtzdVI1mh2I4?p=preview

Sample HTML:

<!DOCTYPE html>
<html ng-app="controllerAsDemo">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c9a8a7aebca5a8bbe7a3ba89f8e7fde7b1">[email protected]</a>" src="https://code.angularjs.org/1.4.0-rc.2/angular.js" data-semver="1.4.0-rc.2"></script>
    <script src="app.js"></script>
  </head>

  <body >
    <p ng-controller="MainController as main">Hello {{main.name}}!</p>
    <p ng-controller="BillyGoatController as billyGoat">Hello {{billyGoat.name}}!</p>
  </body>

</html>

JavaScript code:

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

app.controller('MainController', function() {
  this.name = 'World';
});

app.controller('BillyGoatController', function() {
  this.name = 'Billy Goat Gruff';
})

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

Showing the unique identifier instead of the actual data in HTML for a Firebase Object using Angularfire

Currently, I am utilizing AngularFire for a specific project. The structure of my firebase Object is as follows: { mainKey: { key1:value1, key2:value2 }, mainkey2: { key3:value3 } } The data has been inputted in a manner tha ...

Sides of the BoxGeometry

I previously inquired about a particular issue on this post: Adding Thickness to Faces The main problem has been resolved, but now I have encountered a new issue. Initially, my walls were set to side:THREE.BackSide so they didn't display when facing ...

Using Cordova for mobile applications to play local video files

Our iOS app, developed using PhoneGap / Cordova 4.3.0, loads an external website directly utilizing <content src="http://example.com/foo" /> in the config.xml file. All functionality resides within this website, eliminating the need for local HTML or ...

Automatically insert hyphens in numerical entries for enhanced readability

I have a form with multiple fields that require filtering, such as an SSN field. Currently, I am validating that the user has entered the correct pattern and displaying an error message if necessary. However, users need to input the hyphens themselves. I ...

Enhancing XTemplate in ExtJS 4.2.1 with dynamic data refresh from store

Here's a situation that's quite unique... A DataView linked to a store is causing me some trouble. In the XTemplate, I want to display the quantity of a specific type of JSON record. Each record has a 'type' property with a value. For ...

Get the source of a nested iframe inside a parent iframe

On one of my web pages, I have an iFrame that displays the content of another page with its own embedded iFrame. Unfortunately, I do not have control over this external page. I am wondering if there is a way to extract the src attribute of the nested iFram ...

Prevent the movement of the first column in a table when rearranging rows up or down by utilizing

Feeling a bit stuck here, can't seem to figure out what I've missed. I've managed to move up or down a row in a table, but I need the value of the cell in the first column to remain unchanged. Here's my code: This is my HTML file: &l ...

What is the method for retrieving the active element with Waypoint?

Currently, I am implementing Waypoint (version 7.3.2) in my React project using React version 16. My goal is to create a scrollable list of items where each item fades out as it reaches the top of the container div. My main inquiry is how can I obtain a re ...

Issue with JavaScript function loading website homepage solely is functioning only for the first time

I am in the process of creating my own personal website. To ensure seamless navigation, I added a "home" button that, when clicked, triggers a JavaScript function called loadhomepage() to load the homepage. While this function works perfectly upon initial ...

Could someone clarify why EventEmitter leads to issues with global variables?

I recently encountered an error that took me some time to troubleshoot. Initially, I decided to create a subclass of EventEmitter In the file Client.js var bindToProcess = function(func) { if (func && process.domain) { return process.domai ...

How to Safeguard an AJAX Service Request using jQuery and PHP (with a Session Token)

Currently, I am developing a framework where form submissions are handled through jQuery ajax calls to a .php service file. Here is a snippet of the jQuery code for reference: var dataSerialized = $(form).serialize(); var service = $(form).attr("action") ...

Having trouble with Laravel Vue.js mixins not receiving function responses?

I'm currently working with Laravel 5.8 and Vue.js. I've created a function for handling post/get requests in a more generalized way. However, I'm facing an issue where I am not receiving the expected response from the mixins function. Below ...

SyntaxError: An unidentified item was encountered at the <head> location

I have encountered an issue while loading a PHP file that utilizes ajax. Initially, the page loads without any errors. However, upon triggering the onclick event on a button, I receive the error message "Uncaught SyntaxError: Unexpected identifier" pointin ...

Rearranging information within a JSON structure

Here is a sample of Javascript object and code to consider: Javascript Object { "thing":{ "data":"some data", "thumb":"some data", "data1":"some data", "data2":"some data", "data3":"some data", }, "extra1":[ ...

Exploring the possibility of designing custom pageload tooltips inspired by jQuery validationEngine's visual style and interface

My website incorporates the jQuery.validationEngine plugin to ensure the accuracy of user input. The tooltips that accompany this validation feature are particularly appealing; they gracefully fade in and vanish when users interact with them. To visualize ...

the append function combines existing data with new data

After retrieving data through ajax, I am facing a challenge in displaying it within a UI popup: [{"BadgeImage":"http:\/\/localhost:8666\/web1\/profile\/images\/badge image 2\/1.png"}, {"BadgeImage":"http:\/\/lo ...

Generating a new root in React 18 results in numerous rounds of rendering and execution

Every time I attempt to run this code in React 18, it seems to render multiple times unlike React 17 where it only executes once and functions properly. How can I modify the code so that it only runs once? Is there a specific reason for the multiple execu ...

Tips for integrating NPM Modules with Flask

As I deploy my Python application with Flask using the render_template() function onto a webpage, I am also attempting to integrate some JavaScript modules using npm. Even though I have installed the necessary modules in the static folder along with all my ...

Using $location in a factory is a common practice when working with AngularJS

I have developed a factory that utilizes the $resource factory. I would like to customize the URL parameters passed to the $resource based on my current URL. Here is an example of my code: MyApp.factory("provider_services", ['$resource', functio ...

Retrieve the numerical worth of a specific offspring component

I am currently working with the following HTML structure: <td class=​"prd-var-price"> ​<div class=​"price-total">​ <span class=​"price-unit">​€​</span> ​<span class=​"price-value">​ ...