我是 Angular 新手,所以我希望这个问题不要太愚蠢。
正如标题所示,我希望使用 Angular 和 MVC Controller 中的方法来填充列表。但我不知道如何调用该方法?我尝试过发出 http 请求,但无法让我工作。
我完全迷路了还是像下面这样?
这是列表。
<div ng-app="cardList" ng-controller="CardController"></div>
<p><input type="text" ng-model="test" /></p>
<ul>
<li ng-repeat="x in names | filter:test">
{{x}}
</li>
</ul>
这是脚本。
<script>
var list = $http({ url: "Controllers/CardController/AllCardsList", method: "GET" });
angular.module('cardList', []).controller('CardController', function ($scope) {
$scope.names = [list];
});
最佳答案
试试这个:
<div ng-app="cardList" ng-controller="CardController">
<p>
<input type="text" ng-model="test" />
</p>
<ul>
<li ng-repeat="x in names | filter:test">
{{x}}
</li>
</ul>
</div>
和:
angular.module('cardList', []).controller('CardController', function($scope, $http) {
$http.get("Controllers/CardController/AllCardsList").then(function(response){
$scope.names = response.data;
});
});
关于angularjs - 使用 mvc Controller 方法对列表进行数据绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36476221/