ng-view没有显示任何角度

时间:2017-01-15 18:02:40

标签: angularjs angularjs-directive ng-view

这是我的角度应用程序。

var MyApp = angular.module('myApp', ['ngRoute']);

MyApp.config(function ($routeProvider, $locationProvider) {
    $routeProvider
    .when("/RestChecker", {
        templateUrl: "templates/RestChecker.html",
        controller: "RestController"
    });
    $locationProvider.html5Mode(true);
})

var RestController = function($scope, $log, Rest){
    $scope.restMethod = "get";
    $scope.restURL="https://jsonplaceholder.typicode.com/posts/77";
    $scope.fetchRest = function(){
        Rest.getIt($scope.restURL, $scope.restMethod).then(function(response){
            $scope.response = response.data.body;
            $scope.PostTitle = response.data.title;
            $scope.status = response.status;
            $scope.method = response.config.method;
        },function(response){
            $scope.response = response.data.body;
            $scope.PostTitle = "";
            $scope.status = "";
            $scope.method = "abc";
        });
    };
}

MyApp.controller("RestController", RestController);

这是我的HTML ..

头部内侧。插入基础href标记

<body data-ng-app="myApp">
 <ng-view></ng-view>
<body>

在body标签结束之前。它的

<script src="js/jquery.js"></script>

            <!-- Bootstrap Core JavaScript -->
            <script src="js/bootstrap.min.js"></script>
            <script src="js/angular.min.js"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular-route.min.js"></script>
            <script src="js/responsive/responsive.js"></script>
            <script src="js/responsive/services.js"></script>

我不知道问题出在哪里。只是浪费了我一半的时间来找出解决方案。也在URL中显示

  

http://192.168.0.8:8000/ThemeTemplate.html#%2FRestChecker

知道%2f只是正斜线..

任何建议都表示赞赏。

2 个答案:

答案 0 :(得分:0)

我建议使用&#39; ui-router&#39;。

doc:https://github.com/angular-ui/ui-router

答案 1 :(得分:0)

您的网址为/RestChecker,为什么您要访问/ThemeTemplate.html#%2FRestChecker? 在此处Rest

注入['ngRoute']);

Rest.getIt ???

尝试使用Rest.get