Hatte ein bisschen Probleme mit Angular früher, aber ich war in der Lage, dieses Problem zu lösen. Als Neuling haben wir natürlich mehr Probleme!AngularJS Template nicht richtig geladen
Haben einige nach diesem Fehler gesucht, aber das Anwenden der Korrekturen, die andere Leute versucht haben, hat sich für mich nicht als effektiv erwiesen.
Ich versuche derzeit, eine partielle auf eine Show-Seite in Rails mit AngularJS zu laden. EDIT: Ich entschuldige mich - ich habe vergessen zu erwähnen, dass ich beabsichtige, eine partielle aus einer Datei im selben Verzeichnis wie alle diese Dateien zu laden. Aktuelle Verzeichnisbaum ist wie folgt:
Directory containing relevant js files and the timer partial
Ich habe den folgenden Code, gebaut aus:
Show.html.erb
<timer-info ng-controller = "CountdownController">
</timer-info>
app.js
'use strict';
var myApp = angular.module("summoners-universe", ['ngRoute'])
directives.js
'use strict';
myApp.directive("timerInfo", function(){
return {
restrict: "E",
templateUrl: 'app/assets/javascripts/timer.html'
};
});
controllers.js
'use strict';
myApp.controller('CountdownController',
["$scope", "$http", "$routeParams",
function($scope, $http, $routeParams){
console.log($routeParams);
}]);
Schließlich dieser Controller einen Countdown-Timer angezeigt, aber jetzt wollte ich nur sicherzustellen, dass ich meinen routeParams bekommen könnte und all das.
Leider, ich bin mit dem folgenden Fehler auf Seite Last getroffen:
angular.self-208d6d1….js?body=1:11757 GET http://localhost:3000/games/app/assets/javascripts/timer.html 404 (Not Found)(anonymous function) @ angular.self-208d6d1….js?body=1:11757sendReq @ angular.self-208d6d1….js?body=1:11518serverRequest @ angular.self-208d6d1….js?body=1:11228processQueue @ angular.self-208d6d1….js?body=1:15962(anonymous function) @ angular.self-208d6d1….js?body=1:15978Scope.$eval @ angular.self-208d6d1….js?body=1:17230Scope.$digest @ angular.self-208d6d1….js?body=1:17046Scope.$apply @ angular.self-208d6d1….js?body=1:17338bootstrapApply @ angular.self-208d6d1….js?body=1:1750invoke @ angular.self-208d6d1….js?body=1:4666doBootstrap @ angular.self-208d6d1….js?body=1:1748bootstrap @ angular.self-208d6d1….js?body=1:1768angularInit @ angular.self-208d6d1….js?body=1:1653(anonymous function) @ angular.self-208d6d1….js?body=1:30864fire @ jquery.self-4e23968….js?body=1:3188self.fireWith @ jquery.self-4e23968….js?body=1:3318jQuery.extend.ready @ jquery.self-4e23968….js?body=1:3537completed @ jquery.self-4e23968….js?body=1:3553
angular.self-208d6d1….js?body=1:13551 Error: [$compile:tpload] Failed to load template: app/assets/javascripts/timer.html (HTTP status: 404 Not Found)
http://errors.angularjs.org/1.5.5/$compile/tpload?p0=app%2Fassets%2Fjavascripts%2Ftimer.html&p1=404&p2=Not%20Found
at angular.self-208d6d1….js?body=1:69
at handleError (angular.self-208d6d1….js?body=1:18979)
at processQueue (angular.self-208d6d1….js?body=1:15962)
at angular.self-208d6d1….js?body=1:15978
at Scope.$eval (angular.self-208d6d1….js?body=1:17230)
at Scope.$digest (angular.self-208d6d1….js?body=1:17046)
at Scope.$apply (angular.self-208d6d1….js?body=1:17338)
at done (angular.self-208d6d1….js?body=1:11573)
at completeRequest (angular.self-208d6d1….js?body=1:11779)
at XMLHttpRequest.requestLoaded (angular.self-208d6d1….js?body=1:11712)(anonymous function) @ angular.self-208d6d1….js?body=1:13551(anonymous function) @ angular.self-208d6d1….js?body=1:10226processQueue @ angular.self-208d6d1….js?body=1:15970(anonymous function) @ angular.self-208d6d1….js?body=1:15978Scope.$eval @ angular.self-208d6d1….js?body=1:17230Scope.$digest @ angular.self-208d6d1….js?body=1:17046Scope.$apply @ angular.self-208d6d1….js?body=1:17338done @ angular.self-208d6d1….js?body=1:11573completeRequest @ angular.self-208d6d1….js?body=1:11779requestLoaded @ angular.self-208d6d1….js?body=1:11712XMLHttpRequest.send (async)(anonymous function) @ angular.self-208d6d1….js?body=1:11757sendReq @ angular.self-208d6d1….js?body=1:11518serverRequest @ angular.self-208d6d1….js?body=1:11228processQueue @ angular.self-208d6d1….js?body=1:15962(anonymous function) @ angular.self-208d6d1….js?body=1:15978Scope.$eval @ angular.self-208d6d1….js?body=1:17230Scope.$digest @ angular.self-208d6d1….js?body=1:17046Scope.$apply @ angular.self-208d6d1….js?body=1:17338bootstrapApply @ angular.self-208d6d1….js?body=1:1750invoke @ angular.self-208d6d1….js?body=1:4666doBootstrap @ angular.self-208d6d1….js?body=1:1748bootstrap @ angular.self-208d6d1….js?body=1:1768angularInit @ angular.self-208d6d1….js?body=1:1653(anonymous function) @ angular.self-208d6d1….js?body=1:30864fire @ jquery.self-4e23968….js?body=1:3188self.fireWith @ jquery.self-4e23968….js?body=1:3318jQuery.extend.ready @ jquery.self-4e23968….js?body=1:3537completed @ jquery.self-4e23968….js?body=1:3553
Ich weiß nicht, warum eine GET-Anfrage zu dieser URL gemacht wird. Irgendwelche Gedanken? Vielen Dank!
Feuert aus Ihrer Anweisung "timerInfo". –
Also, wie bekomme ich die VorlageUrl die Datei timer.html rendern, die sich im selben Verzeichnis wie meine Direktiven-Datei befindet? Ich werde mein OP mit korrekten Informationen aktualisieren. –
In templateUrl ist die URL mit dem Präfix "/" relativ zur Domäne, ohne das Präfix "/" relativ zur Hauptseite ("index.html") oder der Basis-URL (wenn Sie den Speicherort im HTML5-Modus verwenden)). Also, es hängt davon ab, wo ist Ihre index.html, wenn ohne html5mode. –