javascript - Angualrjs factor is not working -


i have js

var app = angular.module('myapp', []);  app.factory('data', function () {     return {message: "i data service"} })  app.controller('firstctrl', function ($scope, data) {     $scope.data = data; })  app.controller('secondctrl', function ($scope) {  }) 

and html

<!doctype html> <html ng-app="myapp"> <head>     <title>index</title>     <script src="scripts/angular.js"></script>     <script src="scripts/index.js"></script> </head> <body>       <div ng-controller="firstctrl" >         <input type="text" ng-model="message"/>         <h2>{{message}}</h2>     </div>      <div ng-controller="secondctrl" >         <input type="text" ng-model="message"/>         <h2>{{message}}</h2>     </div> </body> </html> 

when run application, message i data service not loaded h2 of first controller although made factory , passed controller

you assigning $scope.data = data. should access in view

<div ng-controller="firstctrl" >     <input type="text" ng-model="data.message"/>     <h2>{{data.message}}</h2>  </div> 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -