2015-12-05 100 views
1
var app = angular.module('home', []); 

app.controller('articleController', ['$scope', function($scope) { 
    $scope.title = "elad"; 
    $scope.writer = "elad"; 
    $scope.content = "bla bla bla bla bla"; 
}]); 

app.directive('drArticle', function() { 
    return { 
     templateUrl: '/app/shared/article/Views/articleView.html' 
    }; 
}); 

templateUrl正試圖通過這個網址訪問HTML文件:使用templateUrl angularjs

http://127.0.0.1:56911/app/componenets/home/app/shared/article/Views/articleView.html 

該文件實際上位於:

http://127.0.0.1:56911/app/componenets/home/views/index.html

我怎樣才能修復路徑是這樣的:

http://127.0.0.1:56911/app/shared/article/Views/articleView.html 
+0

怎麼樣templateUrl:」 ../../../app/共享/條/查看/ articleView.html」 沒有嘗試過自己 –

+0

我猜你正在創建構建使用一飲而盡/呻吟,從應用程序的多個js文件它創建一個單一的文件,並在文件夾結構得到改變之前,你沒有得到模板。 – Indra

回答

0

關於嘗試這種方式是什麼?

templateUrl: currentScriptPath('articleView.html') 

UPDATE

對不起,我忘了添加一些代碼,結果應該是這樣的:

var currentScriptPath = scripts[scripts.length-1].src; 

var app = angular.module('home',[]); 

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

    $scope.title = "elad"; 
    $scope.writer = "elad"; 
    $scope.content ="bla bla bla bla bla"; 

}]); 

app.directive('drArticle', function() { 
    return { 
     templateUrl: currentScriptPath('articleView.html') 
    }; 
});