Я еще правильно установил jquery с помощью команд:
npm install --save jquery
и
npm i --save @types/jquery
и
npm install -g typings
и
typings install dt~jquery --global –save
Я удалил типизацию папок из проводника файловой системы (потому что код Visual Studio не может удалить его по некоторым причинам), и я удалил файл typings.json. Я также выполнил следующую команду:
npm install --save-dev @types/jquery
Команды были выполнены в терминале кода Microsoft Visual Studio.
Я использую SystemJS для загрузки модулей.
Файл app.ts:
import $ from 'jquery';
(function($) {
// Use $() inside of this function
$("#app").css({"background-color": "green"});
})(jQuery);
Файл app.js:
System.register([], function (exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
(function ($) {
// Use $() inside of this function
$("#app").css({ "background-color": "green" });
})(jQuery);
}
};
});
Файл index.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Learning TypeScript</title>
<script src='node_modules/systemjs/dist/system.js'></script>
</head>
<body>
<div id="app">Change it with jQuery</div>
<script>
System.import('./node_modules/jquery/dist/jquery.min.js');
System.import('./app.js');
</script>
</body>
</html>
Ошибка при выполнении команды tsc.
Иногда jQuery работает нормально, но иногда при нажатии клавиши F5 (страница перезагрузки) в консоли веб-браузера Google Chrome 77.0 появляется следующая ошибка:
Uncaught (in promise) ReferenceError: jQuery is not defined
at Object.execute (app.js:10)
Помогите, пожалуйста, правильно выполнить код jQuery,Большое спасибо заранее.