最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Simple angular.js example sometimes doesn't load - Stack Overflow

programmeradmin0浏览0评论

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

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

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Mar 1, 2015 at 20:14 OndrajZOndrajZ 4674 silver badges19 bronze badges 2
  • Seems to be working fine here: jsfiddle/g33ct2ah Are there no errors in the console? – JLRishe Commented Mar 1, 2015 at 20:19
  • No, there are no errors in javascript console. – OndrajZ Commented Mar 1, 2015 at 20:23
Add a ment  | 

1 Answer 1

Reset to default 14

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.

发布评论

评论列表(0)

  1. 暂无评论