javascript - Service in AngularJS not working -


i working on simplest possible angularjs app based approach understand flow of it. trying pass simple string service controller , there want print string in index.html. seems rest of code working not service , not sure missing here...

index.html

<!doctype html> <html ng-app="angularformsapp">  <head>  <title>angular form</title>  <meta charset="utf-8" />   <link href="content/bootstrap.min.css" rel="stylesheet" />   <script src="scripts/angular.min.js"></script>   <script src="app/angularformsapp.js"></script>   <script src="app/employeeform/efservice.js"></script>   <script src="app/employeeform/efcontroller.js"></script>  <!--<script src="app/employeeform/efdirective.js"></script> --> </head>   <body>      <h1>test angularjs app approach</h1>     <div ng-controller="efcontroller">        {{employee}}    </div>  </body > </html> 

angularformsapp.js (module)

var angularformsmodule = angular.module('angularformsapp', []); 

efcontroller.js (controller)

angularformsmodule.controller('efcontroller',   function efcontroller($scope, efservice) {      $scope.employee = efservice.employee; }); 

efservice.js (service)

angularformsmodule.factory('efservice',  function () {     var employee = "employee detail available";      return employee; }); 

you want return object instead of string.

angularformsmodule.factory('efservice', function efservice() {     var service = {         employee: "employee detail available"     }     return service; }); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -