Question

i have written a simple factory service. here the link to the fiddle http://jsfiddle.net/#&togetherjs=caUQB0merH I am unable to determine why the fiddle is not working. Can any one point out the problem

Thanks in advance

Update:--

  <script>
                var StudentModule=angular.module("StudentModule",[]);
              function  factoryfuc()
                {
                    return[
                            {name:"maclean", age:"22"},
                            {name:"sachin", age:"25"}
                        ];  

                }
                StudentModule.factory('Studentfactory',factoryfuc);

                function StudentController($scope,Studentfactory)
                {
            $scope.students=Studentfactory;

                }
                </script>
            <div ng-app="StudenModule" ng-controller="StudentController">
                <table ng-repeat="student in students"><tr><td>{{student.name}}</td><td>{{student.age}}</td></tr></table>
            </div>
Was it helpful?

Solution

I am using the up-to-date version of Angular and this is working well: http://jsbin.com/eQIVuQi/1/edit

The code I am going to include in this post is your code modified to follow proper naming conventions and better practices.

Markup:

<div ng-app="studentModule" ng-controller="studentCtrl">
  <table ng-repeat="student in students">
    <tr><td>{{student.name}}</td><td>{{student.age}}</td></tr>
  </table>
</div>

JavaScript:

var studentModule = angular.module("studentModule",[]);

studentModule.factory('studentService',function() {
  return [
    {name:"maclean", age:"22"},
    {name:"sachin", age:"25"}
  ];  
});

studentModule.controller('studentCtrl', function($scope, studentService) {
  $scope.students = studentService;
});

Live demo here (click).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top