我想获取用户在文本框中输入的search_name的值。任何人都可以指出错误。
<div ng-controller="AccordionDemoCtrl">
<uib-accordion close-others="oneAtATime">
<uib-accordion-group heading="Search">
<p class="form-group">
<label>Search Name</label>
<input type="text" ng-model="search_name" class="form-control">
</p>
{{search_name}}</br>
<button type="button" class="btn btn-default btn-sm" ng-click="Myfunc()">Search</button>
<table ng-table="tableParams" class="table table-striped" fixed-table-headers="scrollable-area">
<dir-pagination-controls max-size="5" direction-links="true" boundary-links="false" > </dir-pagination-controls>
<tr>
<td>Index </td>
<td>Name</td>
<td>ID</td>
</tr>
<tr ng-repeat="x in names " >
<td>{{ $index + 1 }} </td>
<td>{{ x.NAME }}</td>
<td>{{ x.ID }}</td>
</tr>
</table>
</uib-accordion-group>
</uib-accordion>
</div>
<script type="application/javascript">
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('AccordionDemoCtrl', function ($scope) {
$scope.oneAtATime = true;
$scope.names= {0:{'NAME':'John','ID':'albania'}};
$scope.Myfunc = function() {
console.log($scope.search_name)
console.log($scope.names)
};
当我记录该值时,它表示未定义。
答案 0 :(得分:0)
您是否将$ scope.Myfunc = function()更改为$ scope.Myfunc = function(search_name)?
答案 1 :(得分:0)
您需要将search_name传递给控制器功能。这需要2次更改。
<强>控制器强>
$scope.Myfunc = function(search_name) {
console.log(search_name);
console.log($scope.names);
};
<强> HTML 强>
ng-click="Myfunc(search_name)"