Lumbee Lumbee - 5 months ago 12
AngularJS Question

Trying to run a simple angular app, but angular not loading

I am trying to run this angular app locally: https://jsfiddle.net/alexsuch/6aG4x/

I created an index.html, and an app.js and copied the respective code to each file. In the html file I added...

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<script src= "app.js" type="text/javascript"></script>


I am running http-server from the console to load the app. When I visit localhost:8080 I see the {{ content }} so I know angular is not loading.

Here are my files...

index.html



<!DOCTYPE html>
<html ng-app='store'>
<body>

<div ng-controller="MainCtrl" class="container">
<h1>Select text file</h1>
<input type="file" on-read-file="showContent($fileContent)" />
<div ng-if="content">
<h2>File content is:</h2>
<pre>{{ content }}</pre>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<script src= "app.js" type="text/javascript"></script>
</body>


app.js



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

myapp.controller('MainCtrl', function ($scope) {
$scope.showContent = function($fileContent){
$scope.content = $fileContent;
};
});

myapp.directive('onReadFile', function ($parse) {
return {
restrict: 'A',
scope: false,
link: function(scope, element, attrs) {
var fn = $parse(attrs.onReadFile);

element.on('change', function(onChangeEvent) {
var reader = new FileReader();

reader.onload = function(onLoadEvent) {
scope.$apply(function() {
fn(scope, {$fileContent:onLoadEvent.target.result});
});
};

reader.readAsText((onChangeEvent.srcElement || onChangeEvent.target).files[0]);
});
}
};
});


What am I missing?

Answer

you are bootstrap a module named :'store' with this <html ng-app='store'>

rename myapp to store is this line angular.module('myapp', []);