Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple angular.js example sometimes doesn't load

Problem:

I started using angular.js for my project and during development I noticed that controller sometimes doesn't load, so I tried removing parts of the project until the smallest possible example but the problem still remains.

Code:

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Test</title>
</head>
<body ng-app="myApp">
    <div ng-controller="TestController">
        <input ng-model="testText" type="text" placeholder="Enter text">
    </div>
    <script src="/static/js/angular.js"></script>
    <script src="/static/js/app.js"></script>
</body>
</html>

app.js

console.log("INIT");
angular.module('myApp', [])
.controller('TestController', ['$scope', function($scope) {
    $scope.testText = '172.17.2.1';
    console.log("SCOPE");
}]);

Note:

"INIT" part always gets displayed in console. Altough "SCOPE" part sometimes (or most of the time) doesn't so the input field doesn't get filled.

Versions:

Chrome: 36.0.1985.125

Angular.js: 1.3.14

like image 696
TrueFurby Avatar asked Mar 01 '15 20:03

TrueFurby


People also ask

How do I know if AngularJS is working?

I just opened the console by hitting F12 (or right-clicking and selecting Inspect element , then typed in angular . If you get the message Object {version: Object, callbacks: Object} , angular is loaded. If you get the message Uncaught ReferenceError: angular is not defined , angular is not loaded.

What is not recommended in AngularJS?

It is tempting to do too much work in the AngularJS controller. After all, the controller is where the view first has access to JavaScript via $scope functions. However, doing this will cause you to miss out on code sharing across the site and is not recommended by AngularJS documentation.

Why AngularJS is discontinued?

AngularJS is the first version of the Angular framework, which was released in 2010. All subsequent released versions were called Angular. It had initially planned to end LTS in July 2021, but because of COVID-19, it decided to push that date back by six months to December 31, 2021.

What is $timeout in AngularJS?

The '$timeout' service of AngularJS is functionally similar to the 'window. setTimeout' object of vanilla JavaScript. This service allows the developer to set some time delay before the execution of the function.


1 Answers

Problem was "AngularJS Batarang" extension for Chrome. It was somehow messing up with the angular. I never actually used it, installed it sometime ago when researching angular.js and forgot it enabled.

I disabled it and everything works fine.

like image 179
TrueFurby Avatar answered Oct 03 '22 16:10

TrueFurby