我将在jsbin上显示代码。 问题是:$ scope.name永远不会显示,谢谢
<!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';
});
答案 0 :(得分:1)
快速plnkr
您错过了模块上的ngRoute
依赖项和脚本
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-route.js"></script>
您需要像var test = angular.module('test',['nRoute']);
及其$routeProvider
而非$rootProvider
简单的拼写错误。