Angularjs Module factory service issue

73 views Asked by At

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>
1

There are 1 answers

2
m59 On BEST ANSWER

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).