0

I am trying to run an angularJS example in jsfiddle (ofcourse learning purpose) getting below errors in console.

When I add this cdn for angular compatibility: https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.6/angular.min.js

I seen below error.

VM141 angular.min.js:6 Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.5.6/$injector/modulerr?p0=myApp&p1=Error%3A%2…oudflare.com%2Fajax%2Flibs%2Fangular.js%2F1.5.6%2Fangular.min.js%3A21%3A19)

When I remove the external source, seen below error:

VM93:45 Uncaught ReferenceError: angular is not defined

Concern:

  1. Do I need to add external source for angular example? If yes then what will be the correct way to add external resource. (like, search a cdn for that api and add).

Here's the code snippet:

html:

<div ng-app="myApp" ng-controller="myCtrl">
Your name: <input type="text" ng-model="name" ng-click="displayName();">
Hello {{$scope.name}}
</div>

js:

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

myApp.controller('myCtrl', function($scope){
$scope.displayName = function(){
alert("In right place");
$scope.name = "Name";
}
});

Here's the fiddle: https://jsfiddle.net/supdas87/my1juu4e/2/

4
  • Click on the java script setting button, select a framework and copy the link from cdn or something of that framework and load-type "No-wrap in body" Commented Jul 13, 2016 at 12:26
  • Does this solution solved your problem? Commented Jul 18, 2016 at 10:03
  • Your code is running not mine!! You have changed my code in your way.. What I was thinking is even if my code are logical no problem with that,.. then why it failed to run. @Mistalis Commented Jul 19, 2016 at 11:59
  • Updated my answer to exactly match your code. Commented Jul 20, 2016 at 6:40

1 Answer 1

2

I've added angular-1.0.1.js file to external resources (you just have to copy and paste the URL), and changed {{$scope.name}} by {{name}} on your HTML file. You do not have to write $scope when you use {{ }}, it is implicit.

Here is a working Fiddle based on the code you provided.

PS: I've added Angular 1.0.1, but of course you can use the version of Angular you want. You can see allreleases here.


HTML

<div ng-app="myApp" ng-controller="myCtrl">
  Your name: <input type="text" ng-model="name" ng-click="displayName();">
  Hello {{name}}
</div>

JavaScript

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

myApp.controller('myCtrl', function($scope) {
  $scope.displayName = function(){
    alert("In right place");
    $scope.name = "Name";
  }
});
Sign up to request clarification or add additional context in comments.

3 Comments

What he needed was to know how to setup angularjs source file in jsfiddle, I can't see you explained that here.
give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime :)
@JalalMostafa way to go haha

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.