0

This is my first crack at Angular. I'm posting JSON data to an html page using Angular.js. I know I'm missing something but can't seem to get it working. Below is the html. I have a python script posting to the same URL below.

<!doctype html>
<html lang="en" ng-app id="ng-app">
<head>
<title>File Analysis</title>
<script src="js/angular.js"></script>
<script>
var myApp = angular.module('fileAnalysis', []);
myapp.controller('PostsCtrlAjax', function($scope, $http)
{
$http({method: 'POST', url: 'http://test.com'}).success(function(data)
{$scope.posts = data;}) // response data 
});
</script>
</head>
<body>
<h1>You should begin to see new files being analyzed!</h1>
<div id="ng-app" ng-app ng-controller="PostsCtrlAjax">

<div ng-repeat="post in posts" >
<h2>
<a href='{{post.url}}'>{{post.title}}</a>
</h2>
   <td>
        {{post.filename}}
   </td>
</div>
</body>
</html>
user3285763
  • 157
  • 1
  • 3
  • 14
  • 1
    what you want to achieve by post using `file://` protocol? – Pankaj Parkar May 05 '15 at 18:13
  • 1
    You are missing some integral pieces to make Angular work. First you need to create a module with `angular.module('appName')`. Then you need to register your controller to the app with `angular.module('appName').controller('PostsCtrlAjax', PostsCtrlAjax)`, but these are just your first few problems. – azium May 05 '15 at 18:15
  • @pankajparkar the file:// is my attempt at keeping this local without running a webserver. If need be, I can set up an apache webserver locally. Just wanted to try without it. – user3285763 May 05 '15 at 18:19
  • 1
    @user3285763 you have to host your code somewhere in order to make it working – Pankaj Parkar May 05 '15 at 18:20
  • @azium is appName the url or something else? – user3285763 May 05 '15 at 18:40
  • 1
    [See this](http://stackoverflow.com/a/3397710/492258) – asdf_enel_hak May 05 '15 at 18:41
  • 1
    No, `appName` is the name of your angular module, which you need to instantiate if you want to create a controller function that works. https://docs.angularjs.org/guide/controller – azium May 05 '15 at 18:49
  • @azium any advice on how you would set up a controller for this? I've been going through the documentation but am a bit unsure how to adapt it to this scenario. – user3285763 May 06 '15 at 14:31
  • 1
    [Here's my dead simple angular app](http://codepen.io/alex-wilmer/pen/xGwjrz?editors=101) . You should be able to follow that to create an app, a controller, and make an `$http` request – azium May 06 '15 at 14:50

0 Answers0