angularjs - facing issue using $scope and $rootscope -


i facing issue print text using angualrjs $scope , $rootscope. please find code below , let me know did mistake.

<body ng-app="x">          <div ng-controller="ctrl1">             hello {{name2}}         </div>          <div ng-controller="ctrl2">             hi {{name1}} how {{name3}}         </div>          <script>              var app= angulr.module("x",[]);              app.controller("ctrl1" ,['$scope', '$rootscope',function($scope, $rootscope){                  $scope.name2 = "sir";                 $rootscope.name3 = "are you!";             }]);              app.controller("ctrl2", function($scope){                  $scope.name1 = "madam";             });          </script>      </body> 

please run following code. problem solved. spelled angular incorrectly , dont need put scope , rootscope in bracket in ctrl1 in controller. rootscope , not rootscope (check capital s)

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>  <body ng-app="x">            <div ng-controller="ctrl1">              hello {{name2}}          </div>            <div ng-controller="ctrl2">              hi {{name1}} how {{name3}}          </div>            <script>                var app= angular.module("x",[]);                app.controller("ctrl1" ,function($scope, $rootscope){                    $scope.name2 = "sir";                  $rootscope.name3 = "are you!";              });                app.controller("ctrl2", function($scope){                    $scope.name1 = "madam";              });            </script>        </body>


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -