迁移角度1.4到angularjs 1.5会产生错误

时间:2016-10-26 23:37:13

标签: javascript angularjs

我开始学习angularjs whit这个简单的代码

extension Dictionary {
   func trueKeysDictionary() -> [Key: Bool] {
       var trueKeys = [Key: Bool]()
       self.keys.forEach { trueKeys[$0] = true }
       return trueKeys
   }
}

app.js

<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<script src='https://ajax.googleapis.com/ajax/libs/mootools/1.3.1/mootools-  yui-compressed.js' type='text/javascript'></script>
<script src='assets/js/menuMatic.js' type='text/javascript'></script>
<link rel="stylesheet" href="assets/css/style.css"> 
</head>
<body ng-app="myApp">
<div ng-include="'header.html'"></div>
<div ng-view></div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script src="https://code.angularjs.org/1.5.8/angular-route.min.js"></script>
<script src="js/app.js"></script>
<script src="js/controller/posts.js"></script>
<script src="js/service/post.js"></script>
</body>
</html>

当我使用angularjs 1.2.27它工作正常但是当我使用angularjs 1.5.8它显示我这个错误

var app = angular.module('myApp',['ngRoute'])
    app.config(function($routeProvider){
        $routeProvider
            .when('/',  {templateUrl:'partials/home.html',controller:'PostsCtrl'})          
            .otherwise({redirectTo:'/'});
});

我相信一些全局控制器功能被禁用或者其他东西,但我不知道如何修复
编辑

我使用angularjs版本1.4.8并且它正在工作..但是当我使用1.5.8它不再工作

2 个答案:

答案 0 :(得分:0)

我认为您需要单独将$ rootProvider添加到您的配置中,如下所示:

var app = angular.module('myApp',['ngRoute']);
app.config(['$routeProvider', function($routeProvider){
    $routeProvider
        .when('/',  {templateUrl:'partials/home.html',controller:'PostsCtrl'})          
        .otherwise({redirectTo:'/'});
}]);

答案 1 :(得分:-2)

要么在第一行的末尾加上分号

或删除&#34; 应用&#34;在第二行代码中。

var app = angular.module('myApp',['ngRoute']);
    app.config(function($routeProvider){
        $routeProvider
            .when('/',  {templateUrl:'partials/home.html',controller:'PostsCtrl'})          
            .otherwise({redirectTo:'/'});
});

var app = angular.module('myApp',['ngRoute'])
    .config(function($routeProvider){
        $routeProvider
            .when('/',  {templateUrl:'partials/home.html',controller:'PostsCtrl'})          
            .otherwise({redirectTo:'/'});
});