2015-12-05 62 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') 
    }; 
});