问题
being a newbee to the ionic 2 and Trello REST interface I need help please:
As per the Trello.com site (https://developers.trello.com/get-started/start-building) I have:
Added under the html line in the index.html ie: before the body as they ask, the following and replaced the AppKey in my code:
< script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> < script src="https://api.trello.com/1/client.js?key=[AppKey]"></script>
Added code to add a card as per their example:
var myList = 'myIDLIST';
var creationSuccess = function(data) { console.log('Card created successfully. Data returned:' + JSON.stringify(data)); }; var newCard = { name: 'New Test Card', desc: 'This is the description of our new card.', // Place this card at the top of our list idList: myList, pos: 'top' }; Trello.post('/cards/', newCard, creationSuccess);
However I get a typescript error:
TypeScript error: C:/workspace/...etc..../service.ts(66,9): Error TS2304: Cannot find name 'Trello'.
I thought Trello should be available to other modules since its declared in the index.html
Any help appreciated.
回答1:
The Trello object might exist at runtime, but the Typescript compiler doesn't know about it, so it reports the errors. You have to provide the declaration files or simply tell the compiler that it should expect a global Trello object. For that put this line of code to the beginning of every file that uses the Trello object.
declare var Trello: any;
You can also use the node-trello package and import it directly.
来源:https://stackoverflow.com/questions/38495236/using-trello-rest-in-ionic-2-error-ts2304-cannot-find-name-trello