javascript – 一起使用jQuery和AngularJS?

我是AngularJS的新手,这个项目推动了我对使用ng-repeat和控制器的了解.

目标:当您从下拉菜单中选择一个选项并单击按钮时,吉他将在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"
            }
        ];
    }
}) 
}) 

我希望这不是我错过的一个小错误,但这个程序的总体布局似乎好像可以工作,并且不确定为什么不行.

最佳答案 在这种情况下,JQuery是不必要的,使用它是开始使用AngularJS的一种非常糟糕的方法.如果您打算使用框架,那么最好承诺正确使用它.一个小时或2个小时研究
getting started guide将为您节省很多痛苦.

点赞