2015-08-25 90 views
0

當我嘗試使用角度運行本地項目時,我從Chrome獲得404狀態。我不確定問題所在,我已經嘗試了類似問題的建議答案。

這是我的指令文件:

'use strict'; 

/** 
* @ngdoc directive 
* @name stockDogApp.directive:stkWatchlistPanel 
* @description 
* # stkWatchlistPanel 
*/ 
angular.module('stockDogApp') 
    .directive('stkWatchlistPanel', function ($location, $modal, WatchlistService) { 
    return { 
     templateUrl: 'views/templates/watchlist-panel.html', 
     restrict: 'E', 
     scope : {}, 
     link: function($scope){ 
     $scope.watchlist = {}; 
     var addListModal = $modal({ 
      scope : $scope, 
      template: 'views/templates/addlist-modal.html', 
      show : false 

     }); 

     $scope.watchlists = WatchlistService.query(); 

     $scope.showModal = function(){ 
      addListModal.$promise.then(addListModal.show); 
     }; 
     $scope.createList = function(){ 
      WatchlistService.save($scope.watchlist); 
      addListModal.hide(); 
      $scope.watchlist = {}; 
     }; 
     $scope.deleteList = function(list){ 
      WatchlistService.remove(list); 
      $location.path('/'); 
     }; 
     } 
    }; 
    }); 

這是我的「應用程序」的樹狀視圖文件夾

|-- 404.html 
|-- favicon.ico 
|-- images 
| `-- yeoman.png 
|-- index.html 
|-- robots.txt 
|-- scripts 
| |-- app.js 
| |-- controllers 
| |-- directives 
| | `-- stk-watchlist-panel.js 
| `-- services 
|  `-- watchlist-service.js 
|-- styles 
| `-- main.css 
`-- views 
    `-- templates 
     |-- addlist-modal.html 
     `-- watchlist‐panel.html 

我得到一個頁面沒有找到錯誤,當我加載的index.html在我的控制檯。

Error: [$compile:tpload] Failed to load template: views/templates/watchlist-panel.html (HTTP status: 404 Not Found) 
http://errors.angularjs.org/1.4.4/$compile/tpload?p0=views%2Ftemplates%2Fwatchlist-panel.html&p1=404&p2=Not%20Found 

我也嘗試從根文件夾輸入完整路徑,但它仍然沒有檢測到頁面。

我不確定這是否是原因,但看看Chrome開發人員工具顯示源選項卡沒有應用程序文件夾(它只顯示'bower_components','腳本','樣式'和index.html的

**更新**

看來,這角度無法看到的唯一文件夾是在應用程序的意見文件夾中。我不能確定問題所在。莫不是有繁重的一個問題?

ngtemplates: { 
    dist: { 
    options: { 
     module: 'stockDogApp', 
     htmlmin: '<%= htmlmin.dist.options %>', 
     usemin: 'scripts/scripts.js' 
    }, 
    cwd: '<%= yeoman.app %>', 
    src: 'views/{,*/}*.html', 
    dest: '.tmp/templateCache.js' 
    } 
}, 
+0

這是否運行縮小的代碼?或者只是運行「咕嚕咕嚕」? –

+0

你解決了嗎,因爲如果你這樣做,我卡在它 –

+0

只是重新編寫了整個事情..工作正常,然後出於某種奇怪的原因 – Kannaj

回答

2

我想這是因爲你寫了template: 'views/templates/addlist-modal.html'而不是templateUrl: 'views/templates/addlist-modal.html'

0

我剛剛將你的指令粘貼到我的工作應用程序,它運行良好。你停下來開始咕嚕嗎?請注意第16頁可能會解釋爲什麼不動態獲取目錄。

0
Error: [$compile:tpload] Failed to load template: xyz.html (HTTP status: 404 Not Found) 

可以通過在web.config中

<system.webServer> 
    <handlers> 
     <remove name="BlockViewHandler"/> 
     <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" /> 

由此阻止任何直接請求到瀏覽目錄中的文件下方設置引起的。對此文件的角度xhr請求被阻止。

評論一下,看看事情是否奏效。請謹慎使用它,因爲它允許訪問您的文件。

相關問題