javascript - Angular error with ng-repeat -


the last 3 hours made little app. it's not ready yet, there error. can not figure out, what's wrong.

here html:

<html lang="en" ng-app="reporting"> <head> <meta charset="utf-8" /> <title>.reporting</title>  <!-- bootstrap --> <link href="content/bootstrap.css" rel="stylesheet" /> <!-- bootstrap --> <!-- jquery --> <script src="scripts/jquery-2.1.4.js"></script> <!-- jquery --> <!-- editor --> <script src="scripts/wysihtml5-editor/bootstrap3-wysihtml5.all.min.js"></script> <link href="scripts/wysihtml5-editor/bootstrap3-wysihtml5.css" rel="stylesheet" /> <script src="scripts/wysihtml5-editor/bootstrap3-wysihtml5.min.js"></script> <!-- editor --> <!-- angular --> <script src="scripts/angular.js"></script> <!-- angular --> <!-- custom --> <link href="css/app.css" rel="stylesheet" /> <link href='http://fonts.googleapis.com/css?family=abel' rel='stylesheet' type='text/css'> <!--<script src="js/init.js"></script>--> <script src="js/controller.js"></script> <!-- custom -->  </head> <body> <div id="top" class="row">     <div id="treecontainer" class="col-md-4" ng-controller="treecontroller treectrl">         <header>             <h2>Übersicht, {{treectrl.text}}, {{2 + 2}}</h2>         </header>         <content id="tree">             <ul ng-repeat="knoten in treectrl.treedata">                 <li>h: {{knoten.name}}</li>             </ul>         </content>     </div> </body> </html> 

and here controller.js:

(function () {  var reportapp = angular.module('reporting', []);  reportapp.controller('treecontroller', ['$http', '$scope', function ($http, $scope) { $scope.treedata = [{     "name": "titel",     "id": "1" }, {     "name": "allgemeine standardangaben",     "id": "2" }]; $scope.text = "hallo";  $http.get('../data/tree.json').success(function (data) {     $scope.treedata = data;     console.log($scope.treedata); });  }]); })(); 

the problem is, ng-repeat in html not render. eyerything after content-tag empty. {{treectrl.text}} in headline won't render too. might there wrong scope? watched 2 hours solution can't imagine, be...

thanks suggestions.

solution

here working code. hope, someone:

index.html:

... <div id="treecontainer" class="col-md-4" ng-controller="treecontroller treectrl">         <header>             <h2>Übersicht, {{treectrl.text}}</h2>         </header>         <content id="tree">             <ul ng-repeat="knoten in treedata">                 <li>{{knoten.name}}</li>             </ul>         </content>     </div> ... 

and controller.js:

(function () {  var reportapp = angular.module('reporting', []);  reportapp.controller('treecontroller', ['$http', '$scope', function ($http, $scope) { $scope.treedata = []; $scope.text = "hallo";  $http.get('../data/tree.json').success(function (data) {     $scope.treedata = data; }); }]); })(); 

thanks everybody.

looks need change markup bit. observe following change...

<ul ng-repeat="knoten in treectrl.treedata"> 

=>

<ul ng-repeat="knoten in treedata"> 

treedata defined on $scope. no need call treectrl. likewise, same text well. place {{ text }} in markup.


furthermore, time when need leverage controllername.value syntax when define values on this instead of $scope. example...

reportapp.controller('treecontroller', ['$http', '$scope', function ($http, $scope) {     this.treedata = []; // -- notice this.     .... 

then need syntax have first attempted in markup. stick $scope , won't need it, or can re-factor use this. see blog post - digging angular’s “controller as” syntax more insight on subject


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -