我正在尝试调用已使用 Angular JS 添加到输入的文本,但是在我的控制台日志中我一直未定义。
<div ng-controller="favouritesController" class="col-xs-12 favList">
<input type="text" ng-model="newFav" ng-keyup= "add($event)" class="col-xs-12 FavInput" placeholder="Add A Favourite">
<ul>
<li ng-repeat="weatherList in weatherLists" class="col-xs-12">
<span class="col-xs-12 col-sm-8">{{weatherList._id + ' / ' + weatherList.place}}</span>
<div class="col-xs-12 col-sm-2">
<button type="button" name="button" class="deleFav" ng-click="delete(weatherList)">Delete</button>
<div class="col-xs-12">
<input type="text" ng-model="serverip"/>
<button ng-click="save(serverip)">Save</button>
</div>
</div>
</li>
</ul>
</div>
js代码
myApp.controller('favouritesController', function($scope, $http, $rootScope, $route, $location) {
$scope.save = function(){
console.log($scope.serverip)
}
})
最佳答案
您不需要将参数传递给 save
函数(并且您对 save
的定义不包含该参数)。
将按钮更改为:
<button ng-click="save()">Save</button>
或者接受函数声明中的参数:
$scope.save = function(serverip){
console.log(serverip)
}
关于javascript - 我正在尝试使用 Angular js 从输入中调用文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34233935/