1
所以我有一個自定義指令,使http獲取請求並顯示在另一個模板上。但它不會顯示任何內容自定義指令不顯示任何角度js
的documentdisplay.js文件,其中我已經創建了指令
/**
* @author Karan Shah
*
*/
var documentDisplayModule = angular.module('ald.documentdisplay',[]);
documentDisplayModule.factory('documentDisplayAPI',function(){
var fac ={};
fac.getContents = function($http,docName){
return $htp({
method: 'GET',
url: "/document/getContents/docName?="+docName
});
};
return fac;
});
documentDisplayModule.directive('doccontent', function() {
return {
restrict: 'EA',
scope: {},
replace: true,
link: function ($scope, element, attributes) {
},
controller: function ($scope, $http,$routeParams, documentDisplayAPI) {
documentDisplayAPI.getContents($http,$routeParams.doc).success(function(data,status){
$scope.textofdocument = data;
}).error(function(data,status){
if (404==status){
alert("no text");
} else {
alert("bad stuff!");
}
});
},
templateUrl: "documentcontent.html"
};
});
的html頁面在那裏,我叫它
<!-- @author Karan Shah -->
<body>
<div>
<h1>Document Display Contents</h1>
<doccontent/>
</div>
</body>
和templateUrldocumentcontent.html其中有顯示
<body>
<div>
Hello World
<div>
<a href="#/documents">Back to the List of Documents</a>
</div>
<br>
{{textofdocument}}
</div>
</body>
錯誤,我越來越:
Error: [jqLite:nosel] Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element
http://errors.angularjs.org/1.2.21/jqLite/nosel
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.js:78:12
at JQLite (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.js:2365:13)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.js:6816:27
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.js:8074:11
at deferred.promise.then.wrappedCallback (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.js:11520:81)
at deferred.promise.then.wrappedCallback (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.js:11520:81)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.js:11606:26
at Scope.$RootScopeProvider.$get.Scope.$eval (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.js:12632:28)
at Scope.$RootScopeProvider.$get.Scope.$digest (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.js:12444:31)
at Scope.$RootScopeProvider.$get.Scope.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.js:12736:24)
不顯示內容。我不確定這裏有什麼問題。由於
有在工廠一個錯字:'返回$ htp' – Malk 2014-09-05 17:34:47
我認爲你不應該使用$ HTTP一個指令內。指令是爲了操縱DOM。要從服務器中檢索數據,或將數據發送到服務器,請在控制器或服務器中使用$ http。 – Callebe 2014-09-05 17:39:07
以及咒語更正沒有它運行它makae。我在控制器內部的指令中有$ http。我有另一個頁面可以在相同的情況下正常運行。不知道爲什麼這個不工作。 – 2014-09-05 17:51:51