你好,我有一个Ionic 5 Angular 9项目。我想调用外部javascript文件。这些文件被称为通缉,因为我放置了一个警报,它显示了警报为通缉,但未调用jquery函数
angular.json
import clr
import os
# Verify these are needed.
clr.AddReference('System')
clr.AddReference('System.Drawing')
clr.AddReference("System.Windows.Forms")
# Windows Forms Elements
from System.Drawing import Point, Icon, Color
from System.Windows import Forms
from System.Windows.Forms import Application, Form
from System.Windows.Forms import DialogResult, GroupBox, FormBorderStyle
from System.Windows.Forms import ComboBox, Button, DialogResult
class SelectFromList(Form):
"""
form = SelectFromList(floor_types.keys())
form.show()
if form.DialogResult == DialogResult.OK:
chosen_type_name = form.selected
"""
def __init__(self, title, options, sort=True):
"""
Args:
title (str): Title of Prompt
options (dict): Name:Object
**sort (bool): Sort Entries
"""
self.selected = None
if sort:
options = sorted(options)
# Window Settings
self.Text = title or 'Select View Type'
self.MinimizeBox = False
self.MaximizeBox = False
self.BackgroundColor = Color.White
self.FormBorderStyle = FormBorderStyle.FixedSingle
self.ShowIcon = False
combobox = ComboBox()
combobox.Width = 200
combobox.Height = 20
combobox.DataSource = options
self.combobox = combobox
button = Button()
button.Text = 'Select'
button.Location = Point(0,20)
button.Width = combobox.Width
button.Height = 20
button.Click += self.button_click
self.Width = combobox.Width + 16
self.Height = 80
self.Controls.Add(combobox)
self.Controls.Add(button)
def button_click(self, sender, event):
self.selected = self.combobox.SelectedValue
self.DialogResult = DialogResult.OK
user_test_choice = self.selected
print('User chose test:', user_test_choice)
print('type of user_test_choice:', type(user_test_choice))
print(int(user_test_choice))
#if int(user_test_choice) == 1:
#print("You chose test 1")
#elif int(user_test_choice) == 2:
#print("Oh so you chose test 2")
# elif int(user_test_choice) == 3:
#print("Well done you chose test 3")
#else:
#print("Not sure huh?")
self.Close()
return user_test_choice
def show(self):
""" Show Dialog """
self.ShowDialog()
Application.Run(SelectFromList('Tests to run',{"test1":"1", "test 2":"2", "test 3":"3"}, sort= True))
sortable.js
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/jquery/dist/jquery.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js",
"src/assets/js/bootstrap.min.js",
"src/assets/js/custon.js",
"src/assets/js/charts.js",
"src/assets/js/colors.js",
"src/assets/js/filters.js",
"src/assets/js/global.js",
"src/assets/js/idangerous.swiper.min.js",
"src/assets/js/isotope.pkgd.min.js",
"src/assets/js/jqColorPicker.js",
"src/assets/js/jquery-2.1.4.min.js",
"src/assets/js/jquery-ui.js",
"src/assets/js/jquery-ui.min.js",
"src/assets/js/jquery.canvasjs.min.js",
"src/assets/js/jquery.countTo.js",
"src/assets/js/jquery.easy-autocomplete.min.js",
"src/assets/js/jquery.mixitup.js",
"src/assets/js/jquery.viewportchecker.min.js",
"src/assets/js/magnific.js",
"src/assets/js/map.js",
"src/assets/js/script.js",
**"src/assets/js/sorttable.js",**
"src/assets/js/wow.js"
]
答案 0 :(得分:1)
您可以通过将JavaScript文件添加到index.html文件中来轻松调用它。
<script src="/js/sortable.js"></script>
如果要在ts文件中使用javascript文件
1-将这些导出文件添加到test.js文件中
export { nodes, edges, container, data, options, network };
2-然后将其导入ts文件
import "/js/sortable";
如果要在ngOnInit中使用jquery元素,则必须将其强制转换为任何元素。
if (($('#container-mix') as any).length) {
($('#container-mix') as any).mixItUp({
animation: {
duration: 400,
effects: 'fade translateZ(-360px) stagger(34ms)',
easing: 'ease',
},
});
}