TypeError: 정의되지 않은 속성 'then'을 읽을 수 없습니다.
loginService.islogged()
위의 함수는 "failed"와 같은 문자열을 반환합니다.그러나 실행하려고 하면 에러가 반환됩니다.
TypeError: Cannot read property 'then' of undefined
그리고 커서는 바로 뒤에 표시됩니다.connected그리고 그 전에.then.
다음은 전체 기능입니다.
var connected=loginService.islogged();
alert(connected);
connected.then(function(msg){
alert("connected value is "+connected);
alert("msg.data value is "+msg.data);
if(!msg.data.account_session || loginService.islogged()=="failed")
$location.path('/login');
});
갱신하다
여기 있습니다islogged()기능.
islogged:function(){
var cUid=sessionService.get('uid');
alert("in loginServce, cuid is "+cUid);
var $checkSessionServer=$http.post('data/check_session.php?cUid='+cUid);
$checkSessionServer.then(function(){
alert("session check returned!");
console.log("checkSessionServer is "+$checkSessionServer);
return $checkSessionServer;
});
}
나는 확신해$checkSessionServer를 지정하면 "timeout" 문자열이 생성됩니다.더 이상은 없어요.
약속을 호출 함수로 되돌려야 합니다.
islogged:function(){
var cUid=sessionService.get('uid');
alert("in loginServce, cuid is "+cUid);
var $checkSessionServer=$http.post('data/check_session.php?cUid='+cUid);
$checkSessionServer.then(function(){
alert("session check returned!");
console.log("checkSessionServer is "+$checkSessionServer);
});
return $checkSessionServer; // <-- return your promise to the calling function
}
TypeError: Angular를 사용하여 Django 서비스를 호출할 때 정의되지 않은 속성 'then'을 읽을 수 없습니다.JS.
Python 서비스를 호출하는 경우 코드는 다음과 같습니다.
this.updateTalentSupplier=function(supplierObj){
var promise = $http({
method: 'POST',
url: bbConfig.BWS+'updateTalentSupplier/',
data:supplierObj,
withCredentials: false,
contentType:'application/json',
dataType:'json'
});
return promise; //Promise is returned
}
MongoDB를 데이터베이스로 사용하고 있습니다(상관없다는 것을 알고 있습니다).단, MongoDB + Python (Django) + Angular로 검색하는 경우JS 결과가 나와야 합니다.
함수 내부의 약속 값을 반환합니다.
return new Promise((done, err) => {
......
})
안녕하세요, typscript, testing-library/react를 사용하고 있는 테스트 환경에서도 같은 오류가 발생하고 있습니다.
저는 노드 v14.X를 사용하고 있었는데 다른 사람이 노드 16.X를 사용하고 있었고 그 이상에서는 이 오류가 발생하였습니다.그래서 노드 버전을 업데이트하고 로컬에서 복제할 수 있게 되었습니다.
그런 다음 테스트 파일에서 mockcall을 액트에 추가했습니다.이는 상태 업데이트에도 영향을 미치기 때문입니다.
act(() => {
mockAxios.post.mockImplementation(
async () => Promise.resolve(availabilitySuccessMockData)
);
});
함수에서 약속을 반환해야 합니다.다음과 같습니다.
return new Promise(async (resolve, reject) => {
const { data:users } = await axios("https://jsonplaceholder.typicode.com/users/" + Number);
const { data: posts } = await axios("https://jsonplaceholder.typicode.com/posts?id=1" + Number);
const completeData = [users, posts];
resolve(completeData);
});
언급URL : https://stackoverflow.com/questions/24788171/typeerror-cannot-read-property-then-of-undefined
'programing' 카테고리의 다른 글
| 심각: 미디어 유형=응용 프로그램/json, 유형=클래스 com에 대한 MessageBodyWriter를 찾을 수 없습니다.jersey.jaxb.ToDo, genericType=class com.jersey.jaxb.하기 위해서 (0) | 2023.02.15 |
|---|---|
| Oracle Pl/SQL: XMLTYPE 노드를 통한 루프 (0) | 2023.02.15 |
| MongoDB의 replaceOne()과 updateOne()의 차이점은 무엇입니까? (0) | 2023.02.15 |
| create-react-app은 App.js와 index.js를 모두 생성하는 이유는 무엇입니까? (0) | 2023.02.11 |
| Promise와 AJAX의 차이점은 무엇입니까? (0) | 2023.02.11 |