ng-view
ng-view
是一個與 $route
一起使用的指令,用於在主頁面佈局中呈現區域性檢視。在這個例子中,Index.html 是我們的主檔案,當使用者登陸“/”路線時,templateURL home.html 將在 Index.html 中呈現,其中提到了 ng-view
。
angular.module('ngApp', ['ngRoute'])
.config(function($routeProvider){
$routeProvider.when("/",
{
templateUrl: "home.html",
controller: "homeCtrl"
}
);
});
angular.module('ngApp').controller('homeCtrl',['$scope', function($scope) {
$scope.welcome= "Welcome to stackoverflow!";
}]);
//Index.html
<body ng-app="ngApp">
<div ng-view></div>
</body>
//Home Template URL or home.html
<div><h2>{{welcome}}</h2></div>