2013-11-20 99 views
1

我經歷了this教程。現在我試圖納入要求結合角度與要求

我找到this的解釋。

我目前得到一個錯誤

Object #<Object> has no method 'unshift' 

這是導致錯誤的代碼

require(['jquery', 'angular', 'app/routes/app'], function ($, angular, mainRoutes) { 
    //tried this way as well 
    //$(function() { // using jQuery because it will run this even if DOM load already happened 
    // angular.bootstrap(document, ['mainApp']); 
    //}); 
    require(['Scripts/app/modules/mainApp.js'], function (mainApp) { 
     angular.bootstrap(document.body, [mainApp]);//based of orginal answer 
    }) 
}); 

我app.js文件

define(['app/modules/mainApp', 'app/controller/controllers'], function (mainApp) { 
    return mainApp.config(['$routeProvider', function ($routeProvider) { 
    $routeProvider. 
     when('/phones', { 
     templateUrl: 'Templates/phone-list.html', 
     controller: 'PhoneListCtrl' 
     }). 
     when('/phones/:phoneId', { 
     templateUrl: 'Templates/phone-detail.html', 
     controller: 'PhoneDetailCtrl' 
     }). 
     otherwise({ 
     redirectTo: '/phones' 
     }); 
    }]); 
}); 

和我mainApp.js文件

define(['angular', 'angular-resource'], function (angular) { 
    return angular.module('mainApp', ['ngResource']); 
}); 

還有其他的文件,我沒有顯示(控制器,服務),但我不認爲問題的關鍵在於他們的

UPDATE

我現在越來越不確定注射器的錯誤。

這是被擊中的唯一斷點,但該項目不是未定義的。 enter image description here

更新2

我更新了我的項目,現在越來越像this

我main.js是這個

require.config({ 
    baseUrl: '/Scripts/', 
    urlArgs: "bust=" + (new Date()).getTime(), 
    paths: { 
    'jquery': 'lib/require-jquery', 
    'angular': 'lib/angular/angular.min', 
    'angular-resource': 'lib/angular/angular-resource.min', 
    }, 
    shim: { 
    'angular': { 'exports': 'angular' }, 
    'angular-resource': { deps: ['angular'] }, 
    'jQuery': { 'exports': 'jQuery' }, 
    }, 
    priority: [ 
    'angular' 
    ] 

}); 

require(['angular', 'app/modules/app', 'app/routes/routes'], function (angular, app, routes) { 
     var $html = angular.element(document.getElementsByTagName('html')[0]); 
     angular.element().ready(function() { //breakpoint here 
      $html.addClass('ng-app'); 
      angular.bootstrap($html, [app.name]); 
     }); 
    }); 

,如果我把一個破發點角元素和在控制檯上運行測試

(app == routes) 
true 

應該等於路由嗎?

回答

6

引導方法的第二個參數應該是一個數組,我對下面的代碼進行了更改。

require(['jquery', 'angular', 'app/routes/app'], function ($, angular, mainRoutes) { 
    //tried this way as well 
    //$(function() { // using jQuery because it will run this even if DOM load already happened 
    // angular.bootstrap(document, ['mainApp']); 
    //}); 
    require(['Scripts/app/modules/mainApp.js'], function (mainApp) { 
     angular.bootstrap(document.body, [mainApp]); 
    }) 
}); 
+0

已採取固定的原始錯誤,但現在我得到一個新的錯誤。 –

+0

發生文件錯誤 –

+0

我更新了屏幕截圖 –