var sig = angular.module('sig', ['ngRoute']);
sig.config([ '$routeProvider', function($routeProvider) {
$routeProvider.when('/search/:sig', {
template : ' ',
controller : 'sigSearchResults'
}).when('/', {
template : ' ',
controller : 'sigSearchResults'
}).otherwise({
redirectTo : '/'
});
} ]);
sig.controller('sigSearchResults', function($scope,$log,$http,$q,$routeParams, $window) {
console.log($routeParams);
//code that populates ng-grid to gridOptions element.
});
<html ng-app="sig">
<body ng-controller="sigSearchResults">
<div class="contentContainer">
<div ng-view></div>
<!-- This is the template for the result -->
<script type="text/ng-template" id="sig-search-result-id" >
<div ng-show="loading" style='clear:both; text-align: center;'>Loading report...<img src="../media/images/Wait3.gif"></div>
<div ng-show="!loading" class="gridStyle" ng-grid="gridOptions"></div>
</script>
</div>
答案 0 :(得分:2)
是的,当您使用ng-controller="sigSearchResults"
配置路由和视图时,从<body>
标记中删除$routeProvider
,看起来您的控制器不应该在顶级。
看起来你所缺少的只是路线配置中的tempateUrl
,即
when('/', {
templateUrl: 'sig-search-result-id',
controller: 'sigSearchResults'
})