gpt4 book ai didi

javascript - 一起使用 jQuery 和 AngularJS?

转载 作者:搜寻专家 更新时间:2023-10-31 08:52:06 25 4
gpt4 key购买 nike

我是 AngularJS 的新手,这个项目插入了我已经知道的关于使用 ng-repeat 和 Controller 的知识。

目标:为了做到这一点,当您从下拉菜单中选择一个选项并单击按钮时,吉他将在 ng-repeat 的帮助下显示.目前,只会显示名称,但我专注于确保 app.js 文件正常工作。

HTML :

<!DOCTYPE html>
<html>

<head>

<title>Angular Project 2</title>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="app.js"></script>

</head>


<body ng-app="myApp">
<header ng-controller="HeaderCtrl">
<h1 id="title">{{appDetails.title}}</h1>
<h3 id="tagline">{{appDetails.tagline}}</h3>
</header>


<select id="dropdown">
<option value="Yamaha">Yamaha</option>
<option value="Gibson">Gibson</option>
<option value="Jackson">Jackson</option>
<option value="ESP">ESP</option>
</select>

<br>

<input type="submit" id="searchGuitars" value="Search!">

<section id="bookSection" ng-controller="GuitarCtrl">
<div ng-repeat="guitar in guitars">
{{guitar.title}}
</div>
</section>
</body>
</html>

JS :

var app = angular.module("myApp", []);

app.controller("HeaderCtrl", function ($scope) {
$scope.appDetails = {
title: "JamLog",
tagline: "Take a look at our Fancy Instruments in Stock!"
};
})

app.controller("GuitarCtrl", function ($scope) {

$('#searchGuitars').click(function() {

if ($('#dropdown').val() == "Yamaha") {

$scope.guitars = [

{
title: "Yamaha Revstar 420",
instrument: "Electric Guitar",
color: "Red",
price: "$499.99",
details: "Yes",
imageURL: "YamahaRS420.jpg"
},

{
title: "Yamaha Pacifica Series PAC012",
instrument: "Electric Guitar"
color: "Blue",
price: "$",
details: "Yes",
imageURL: "YamahaPacificaSeriesPAC012.jpg"
}
];
}

else if ($('#dropdown').val() == "Gibson") {

$scope.guitars = [

{
title: "Gibson Les Paul Custom",
instrument: "Electric Guitar",
color: "Blue",
price: "$",
details: "Yes",
imageURL: "GibsonLesCustomBlue.jpg"
},

{
title: "Thunderbird",
instrument: "Bass",
color: "Black",
price: "$",
details: "Used by SOAD Bassist",
imageURL: "GibsonThunderbirdIV.jpg"
}
];
}
})
})

我希望这不是我遗漏的一个小错误,但该程序的总体布局似乎可行,但我不确定为什么不行。

最佳答案

请尝试在 Angular 之前声明 JQuery CDN https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js

关于javascript - 一起使用 jQuery 和 AngularJS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39865338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com