Sarjan Desai
Sarjan Desai

Reputation: 3733

Angularjs not working in windows chrome and firefox after writing own code

Below are two scenario for problem:

1) The issue is I'm facing is if I write some answer at here and I want to add demo example for angularjs using snippet. When I add proper working code for angularjs, includig script file on snippet and press run. Nothing is working. No console error. Everything is loaded including angularjs script file.

Now if I add that snippet into my answer and check it in my laptop, it's working fine or if I check my own answer after reloading that page, snippet is working fine which was not working when I try to write some code on snippet for answer.

Same thing happen when creating fiddle.

2) Link for Fiddle

If I try to open above fiddle link in new tab then fiddle is working fine.

But problem is If I copy same code from fiddle and create new fiddle with same code, add angularjs script and try to run it, it's not binding scope value to html and return below output

If you change the value with the arrows ng-change doesn't work on the first change. [SHOW ONE DROPDOWN WITH NO OPTION]  {{selected}}

Question: How I can solve this problem and make angularjs up and running?

Upvotes: 0

Views: 3617

Answers (2)

Sarjan Desai
Sarjan Desai

Reputation: 3733

I found the solution and the solution is by adding ng-app in starting of div/html makes my example working which I was always not adding. It is working in fiddle and in snippet also.

In question's fiddle, there is default ng-app already added so working that fiddle working fine but by creating new fiddle ng-app will not added by default so not working but by adding it manually it's working fine.

var application = angular.module('myApp', []);
application.controller('myController', function($scope) {
    $scope.myData = 'It\'s Working ';
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myController">
    {{myData}}
</div>

Upvotes: 1

show-me-the-code
show-me-the-code

Reputation: 1553

From your description, it looks like AngularJS library is not loaded in your environment. Make sure you have included it in the body of your HTML page.

Also regarding the problem in your jsFiddle which doesn't work when you copy paste an existing working fiddle, you need to select the proper library and to change its loading behavior from onLoad to No-wrap - in <body>. When you click on a working fiddle it works, because these preferences are pre-loaded. When you create a new one, you probably don't change the default, which onLoad.

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.1/angular.min.js"></script>

Upvotes: 0

Related Questions