【发布时间】:2019-10-20 11:58:11
【问题描述】:
我正在尝试在选择下拉菜单中的 Pug 文件中编写一个用于 ng-change 的函数。
此函数需要更新表 (id = availableFlight) 以显示目的地与从下拉列表中选择的航班匹配的所有航班的列表。
这使用了我以前很少使用的 Angular,并且 HTML 是 PUG。
这是我目前所拥有的
JS 文件:
angular.module("app",[]).controller("myFlight",function($scope){
$scope.destinations = ["Florida", "New York", "Venice"];
$scope.flights = [
{
company: "British Airways",
company: "EasyJet",
company: "Virgin"
},
{
destination: "Florida",
destination: "New York",
destination: "Venice"
},
{
class: "Economy",
class: "Business",
class: "Business"
},
{
price: "£2000",
price: "£4000",
price: "£6000"
},
{
airMiles: "3000",
airMiles: "1200",
airMiles: "9000"
}
];
// the function I am trying to create -
$scope.updateTable = function(){
}
});
这是 PUG 文件 -
div(ng-app='app', ng-controller='myFlight')
.container
h1 My Flight
h3 Select a destination:
select(ng-model="selectedName" name="destinationList" id='destinationList' ng-change='updateTable()' ng-options="destination for destination in destinations")
option(value='FL') Florida
option(value='NY') New York
option(value='VCE') Venice
table.table(id='availableFlight')
thead
tr
th Destination
th company
th class
th price
th airMiles
tbody(ng-repeat='flight in destinationfilter' ng-show='destinationfilter')
tr
td {{flight.destination}}
td {{flight.company}}
td {{flight.class}}
td {{flight.price | currency:"£"}}
td {{flight.airMiles}}
td
a
i.fas.fa-long-arrow-alt-right(ng-click='selectedFlight(flight)')
h1 Flight Selected
h5 {{flightSummary.destination}}
p Company: {{flightSummary.company}}
span how many passengers :
input(id="number" min=1 type="number" ng-model='howMany' ng-change='updatePrice()')
p total price {{priceTotal |currency:"£"}}
任何帮助将不胜感激。 非常感谢
【问题讨论】:
-
首先阅读基本的 JavaScript。一个对象可能只包含唯一键
-
你真的应该,如果你已经知道 javascript,使用 angular 会更有趣。此外,由于您似乎刚刚开始使用 angular - 您使用的是版本 1,但当前版本是 8
-
是的,我正在使用版本 1 进行练习,所以我想使用版本 1 而不是 8 来完成它。谢谢。
标签: javascript angularjs pug