1

Sorry to bother... but I am blue in the face and dying of asphyxiation from this.

Ok I am using eclipse and relevent angular plugins to edit a simple list example as follows but it refuses to display on preview or when opened with browser within eclipse.

This one came right out of the book keyed in as-is... ok except for double quotes vs single quotes... the eclipse plugin reacts differently to those... but I dont know why or what takes precedence for these quotes. It seems to like the single quotes better.

Anyway, this JSON list wont display.

Any tips ? Thanks

<script>
    alert ('inside js');

    var myModule.controller('AppCtrl', function($scope) { });
    myModule.controller('AppCtrl', function($scope) {
        $scope.stories = [
            {title:'Story 00', description:'Description pending.'},
            {title:'Story 01', description:'Description pending.'},
            {title:'Story 02', description:'Description pending.'},
            {title:'Story 03', description:'Description pending.'},
            {title:'Story 04', description:'Description pending.'},
            {title:'Story 05', description:'Description pending.'}
            ];
        });
</script>

<div ng-controller='AppCtrl'>
    <div class='span4 sidebar-content'>
        <h2>Stories</h2>
        <div class='story' ng-repeat='story in stories' > 
            <h4>{{story.title}}</h4>
            <p>{{story.description}}</p>
        </div>
    </div>
</div>

<script type="text/javascript" 
      src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular.min.js"></script>

3
  • What is the following code supposed to do var myModule.controller('AppCtrl', function($scope) { }); ? Commented Sep 19, 2014 at 20:56
  • 1
    That;s one awful book. Commented Sep 19, 2014 at 20:56
  • @Kent I've dealt with the issues in your code. Please don't take offense, but realize that it is very unreasonable to try to debug your Eclipse problem here and it is off-topic for a Stack Overflow post. This sounds like something you need to discuss with the plugin author or some support forum related to eclipse. Commented Sep 20, 2014 at 1:00

2 Answers 2

2

The problem is that you are not creating an angular module, nor are you bootstrapping that module and for some reason, you have the controller declaration duplicated. This is a working example with those corrections:

// declare an angular module
angular.module('myApp', [])

// attach controller
.controller('AppCtrl', function($scope) {
  $scope.stories = [
    {title:'Story 00', description:'Description pending.'},
    {title:'Story 01', description:'Description pending.'}
  ];
})

;

Markup:

<!-- bootstrap the angular module and add controller to element -->
<div ng-app="myApp" ng-controller='AppCtrl'>
    <div class='span4 sidebar-content'>
        <h2>Stories</h2>
        <div class='story' ng-repeat='story in stories' > 
            <h4>{{story.title}}</h4>
            <p>{{story.description}}</p>
        </div>
    </div>
</div>

Live Demo

You may cache the module to a variable, but I see no need to do so. Angular is already a global variable - I suggest using it's internal module system to store and get references to modules rather than making more globals.

// make a module
angular.module('myModuleName', [
 // array of dependencies
]);

// get a module
angular.module('myModuleName')
// add a controller to the module
.controller('myCtrl', function() { //etc

Rather than:

var myModule = angular.module('myModuleName', []);
myModule.controller(function() {
Sign up to request clarification or add additional context in comments.

4 Comments

i run your code in eclipse using the plugin editor and it hangs
ok, i cut your code from my eclipse editor as-is and pasted it into a new jsbin editor on web... and it doesnt run... i am seeing what I originally saw... no rendering
i cant add or edit js code without the Angular eclipse plugin hanging and crashing the whole IDE
thanks for the working example...i am going to shake this out one way or another...binary edit characters or unstable plugin...i will post something working soon
0

At this attempt you've missed ng-controller and ng-app in your HTML here is working jsbin http://jsbin.com/qeninogakeji/1/edit

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="appViewModule">
  
    <div class='span4 sidebar-content' ng-controller="AppViewController">
        <h2>Stories</h2>
        <div class='story' ng-repeat='story in stories' > 
            <h4>{{story.title}}</h4>
            <p>{{story.description}}</p>
        </div>
    </div>
</div>
<script>
var appViewModule = angular.module('appViewModule', []);

    appViewModule.controller('AppViewController', function($scope) {
      
        $scope.stories = [
            {'title':'Story 00', 'description':'Description pending.'},
            {'title':'Story 01', 'description':'Description pending.'},
            {'title':'Story 02', 'description':'Description pending.'},
            {'title':'Story 03', 'description':'Description pending.'},
            {'title':'Story 04', 'description':'Description pending.'},
            {'title':'Story 05', 'description':'Description pending.'}
            ];
        });

</script>

3 Comments

@Kent please copy code from my answer to your solution it should works, as you can see it's working here
yeah I saw it worked here... can you post my code snippet to see that it works here too? I am not sure how to get the RUN/HIDE buttons to show on this post.
ok nice, thats what I was seeking... a 1 pager example... but it seems coding anything in the head tag doesnt want to fly, at least with the eclipse plugin. I cut/copied your update to eclipse and it ran fine. THANK YOU... and sorry moderator... feel free to clean up... I will keep things concise and this is actually my first time feeling out stackoverflow. - cheers

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.