[英]passing ng-model variable through an ng-click to a function
我正在嘗試使用帶有HTML的select和options標記。 使用ng-repeat
,當用戶從列表中選擇項目並按下獲取按鈕時,我想將用戶從選項列表中選擇的內容傳遞到使用ng-click
的函數中
HTML
<ul>
<li class="col-xs-4"><a href="#favourites">Favourites</a></li>
</ul>
<div ng-controller="favouritesController">
<select class="col-xs-12" name="weather">
<option ng-repeat="weatherList in weatherLists" ng-model="city">{{weatherList.place}}</option>
</select>
<div class="col-xs-12">
<button type="button" name="button" class="deleFav" ng-click="getFavWeather(city)">Get</button>
</div>
</div>
Javascript代碼
var myApp = angular.module('myApp', ['ngRoute'])
myApp.controller('favouritesController', function($scope, $http, $rootScope, $route, $location) {
$scope.getFavWeather = function(weatherList){
console.log("yes yes yes")
console.log($scope.city)
}
})
在選擇中添加ng-model並在ng-click中使用它:
<div ng-controller="favouritesController">
<select class="col-xs-12" name="weather" ng-model="citySelected">
<option ng-repeat="weatherList in weatherLists" ng-model="city">{{weatherList.place}}</option>
</select>
<div class="col-xs-12">
<button type="button" name="button" class="deleFav" ng-click="getFavWeather(citySelected)">Get</button>
</div>
</div>
做這樣的事情:
<label class="item item-input">
<textarea placeholder="Comments" ng-model="textModel" ></textarea>
</label>
<a class="button button-positive" ng-lick="closeModal(textModel)">Save</a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.