Daniel.Woo
Daniel.Woo

Reputation: 636

why I can't get value from controller scope with ng-view

I will show you the code on jsbin. the issue is : $scope.name never show,thank you

http://jsbin.com/buwij/1/edit

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body ng-app="test">
  <a href="#/you">go to</a>
  <ng-view></ng-view>
  <script type="text/ng-template" id="you.html">
    {{name}}
  </script>
</body>
</html>

js:

var test = angular.module('test',[]);
test.config(function($rootProvider){
  $rootProvider
    .when('/you',{
      templateUrl: 'you.html',
      controller: 'youCtrl'
    });
});

test.controller('youCtrl',function($scope){
  $scope.name = 'you';
});

Upvotes: 0

Views: 419

Answers (1)

David Chase
David Chase

Reputation: 2073

Heres a quick plnkr

You were missing the ngRoute dependency and script on your module

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-route.js"></script>

and you need to setup your module like so var test = angular.module('test',['nRoute']);

and its $routeProvider not $rootProvider simple spelling error.

Upvotes: 1

Related Questions