0

我写了一个简单的工厂服务。这里是小提琴的链接 http://jsfiddle.net/#&togetherjs=caUQB0merH 我无法确定小提琴为什么不起作用。谁能指出问题

提前致谢

更新: -

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

1 回答 1

3

我正在使用最新版本的 Angular,并且运行良好:http: //jsbin.com/eQIVuQi/1/edit

我将在这篇文章中包含的代码是您修改后的代码,以遵循正确的命名约定和更好的实践。

标记:

<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;
});

现场演示(点击)。

于 2013-12-06T07:19:21.870 回答