【问题标题】:AngularJS Routing not working. Getting blank outputAngularJS 路由不起作用。获得空白输出
【发布时间】:2014-12-06 17:20:14
【问题描述】:

我不确定为什么路由不起作用。 View1.html 包含一个简单的网页,view2.html 也是如此。 view1.html 和 view2.html 都位于名为 partials 的文件夹中,“angular-route.js”和“angular-route.min.js”位于主文件夹中名为 node_modules 的文件夹中。我正在使用 ubuntu 14.04。

<script src="scripts/angular.min.js"></script>

<script src="/node_modules/angular-route/angular-route.js"></script>
<script src="/node_modules/angular-route/angular-route.min.js"></script>


<script>
    var demoApp = angular.module('demoApp', ['ngRoute']);

    demoApp.config( function ($routeProvider) {
        $routeProvider
            .when('/',
            {
                controller: 'SimpleController' ,
                templateUrl: 'partials/view1.html' //
            })
            .when('/view2',
            {
                controller: 'SimpleController' ,
                templateUrl: 'partials/view2.html'
            })
            .otherwise({ redirectTo : '/' })
    })

    demoApp.controller('SimpleController', function ($scope)
        {


$scope.customers = [{name:'nihal',city:'hyderabad'},{name:'nihal',city:'mumbai'}, {name:'john',city:'bangalore'}]
        $scope.addCustomer = function() {
            $scope.customers.push({name: newCustomer.name , city: newCustomer.city })
        }
    })


</script>
</body>
</html>

【问题讨论】:

  • 这里有同样的问题。但是我的页面在初始状态下显示 view2。寻找答案

标签: angularjs angularjs-routing angularjs-ng-route


【解决方案1】:

您的路由语法不正确,控制器属性后缺少逗号。

【讨论】:

  • 谢谢。出现语法错误。我纠正了它。还是不行。
  • 你找出问题所在了吗?在遵循 Dan 的 60 分钟角度教程时,我遇到了确切的问题
猜你喜欢
  • 2016-05-03
  • 2016-05-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-02
  • 2018-03-18
  • 2016-09-24
相关资源
最近更新 更多