1

I'm new to angular. Just trying to replicate this jsfiddle to play with nodes, but the angular is not working. First, the jsfiddle is confusing my as the application names are not he same. Secondly, it looks like and old version. What am I doing wrong when setting up the application. Is something missing with the templates, or the order of scripts out of place?

<html> <head> <script src="https://code.angularjs.org/angular-1.0.0rc8.js"></script> <style> ul { list-style: circle; } li { margin-left: 20px; } </style> </head> <body> <script type="text/ng-template" id="tree_item_renderer.html"> {{data.name}} <button ng-click="add(data)">Add node</button> <button ng-click="delete(data)" ng-show="data.nodes.length > 0">Delete nodes</button> <ul> <li ng-repeat="data in data.nodes" ng-include="'tree_item_renderer.html'"></li> </ul> </script> <ul ng-app="Application" ng-controller="TreeController"> <li ng-repeat="data in tree" ng-include="'tree_item_renderer.html'"></li> </ul> <script> angular.module("myApp", []). controller("TreeController", ['$scope', function($scope) { $scope.delete = function(data) { data.nodes = []; }; $scope.add = function(data) { var post = data.nodes.length + 1; var newName = data.name + '-' + post; data.nodes.push({name: newName,nodes: []}); }; $scope.tree = [{name: "Simon", nodes: []}]; }]); </script> </body> </html> 
3
  • If you're trying to learn angular, you may want to start with angular 2+ and not angularjs (unless you're trying to learn it for a job/project that uses it). angular.io/guide/quickstart Commented Jul 20, 2017 at 21:43
  • I was going to rewrite this to angular 2, after I got it to work. Commented Jul 20, 2017 at 21:45
  • 1
    angularjs and angular2 are very very different. Angular2 is a total rewrite of angular and a lot of concepts from angularjs don't carry over to angular 2. But to help you out with angularjs, I am noticing that you're pulling down a very very old version of angularjs. Here's the link to the latest source: code.angularjs.org/1.6.5/angular.js Commented Jul 20, 2017 at 21:46

1 Answer 1

1

ng-appshould target a module. Try ng-app="myApp".

Sign up to request clarification or add additional context in comments.

3 Comments

That's what I thought. However in the fiddle it works.
In the fiddle the module name and the ng-app expression matches, angular.module("Application", []) and ng-app="Application". The module name can be chosen as you like. It just needs to match the ng-app expression.
Sorry, I changed that. The fiddle actually doesn't work when those are matching. See again. It's real weird.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.