2015-02-11 76 views
0

這裏是我的應用程序,試圖使用用戶界面模式,但當模態功能不能找到HTML模板。我可以控制日誌裏面的功能,但不能打開模態視圖。我的角度用戶界面模式不能找到模板

var app = angular.module('myApp', [ 
     'angularUtils.directives.dirPagination', 

    'ui.bootstrap' 
    ]); 


    app.controller('galleryCtrl', ['$scope', '$http', function ($scope, $http) { 

    }]). 
    controller('ModalInstanceCtrl',['$scope','$modal',function($scope, $modalInstance){ 

    }]). 
    directive('myGallery', function ($http,$modal) { 
     return { 
      restrict: 'E', 
      scope: { 
       feed: '@', 
       search: '=?', 
       resultsPerPage: "=?", 
       sorting: "=?" 
      }, 
      templateUrl: './MyGallery.tpl.html', 
      link: function (scope, element, attrs) { 


       scope.search = scope.search || true; 
       scope.sorting = scope.sorting || true; 
       scope.resultsPerPage = scope.resultsPerPage || 10; 

       console.log(scope.resultsPerPage); 

       scope.openModal = function() { 


        var modalInstance = $modal.open({ 
         templateUrl: '/views/modal.html', 
         controller: 'ModalInstanceCtrl' 
        }); 
       }; 
在HTML

<div class="imgs"> 
    <ul> 
     <li dir-paginate="img in imgs 
     | filter:query 
     | itemsPerPage: resultsPerPage.value || 10 "> 
       <a href=""><img ng-src="{{img.url}}" ng-click="openModal()"></a> 
     </li> 
    </ul> 
</div> 

,這就是我得到:

GET http://localhost:63342/views/modal.html 404 (Not Found) 

的路徑是100%正確的,所以如果能跟大家可以看到有什麼問題。

+0

如果您在瀏覽器中直接訪問http:// localhost:63342/views/modal.html,它會將模板拉出來? – duhseekoh 2015-02-11 18:37:23

+0

不,這就是根:mainFolder - > views - > modal.html和index.html中的mainFolder – 2015-02-11 18:57:37

+0

右..所以路徑是不正確的。 '''templateUrl:'yourmainfolder/views/modal.html''''? – duhseekoh 2015-02-12 20:15:54

回答

0

只是爲了確保..嘗試:

templateUrl: 'views/modal.html', 

也許你的本地服務器的文檔根目錄,你覺得是不是這樣的。

擺脫初始斜槓,確保路徑相對於角項目的根文件夾。

+0

我得到這個沒有/:GET http:// localhost:63342/front_testV2/template/modal/window.html 404(Not Found),我根本不知道這個根。有任何想法嗎 ? – 2015-02-11 19:00:15

+0

您必須將您的服務器根目錄配置爲角項目的根目錄。 – joanllenas 2015-02-12 11:35:18