小编The*_*hea的帖子

在Angular JS中,使用带有ng-options的select作为过滤器.如何创建"全部"选项?

我的控制器中有以下数据:

$scope.breeds = ["Poodle", "Collie", "German shepherd"];

$scope.dogs = [
        { name: "Bingo", breed: "Poodle" },
        { name: "Lassie", breed: "Collie" },
        { name: "Bert", breed: "German shepherd" },
        { name: "Lily", breed: "Poodle" },
        { name: "Obi-Wan", breed: "Collie" }
    ];
Run Code Online (Sandbox Code Playgroud)

这是我的HTML:

<select ng-model="query.breed" ng-options="breed for breed in breeds">                                    
    <option value="">All breeds</option>
 </select>

   <table>
        <thead>
            <tr>
                <th>Name</th>
                <th>Breed</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="dog in dogs |filter:query">
                <td>{{dog.name}}</td>
                <td>{{dog.breed}}</td>
            </tr>
        </tbody>
    </table>
Run Code Online (Sandbox Code Playgroud)

一切正常 - 当我选择Collie时,会显示品种为=="Collie"的物品,等等.但我无法弄清楚如何使"所有品种"选项有效.

angularjs

9
推荐指数
1
解决办法
5952
查看次数

Angular Xhr发布对Asp.Net Web API的请求结果参数为null

我已经创建了一个ASP.Net API控制器,我正在尝试使用Angular发出POST请求.请求到达我的控制器方法,但参数值为null.

我的角色代码:

$http({ method: 'POST', url: '/api/Contents', data: "value=foobar", headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }).
    success(function(data) {
                }).
    error(function(data, status, headers, config) {

    });
Run Code Online (Sandbox Code Playgroud)

我也试过json(Json是我最想要的):

$http({ method: 'POST', url: '/api/Contents', data: { "foo": "bar", "foo2": "bar2" }, headers: { 'Content-Type': 'application/json'} }).
    success(function(data) {
                }).
    error(function(data, status, headers, config) {

    });
Run Code Online (Sandbox Code Playgroud)

我的(非常简单)Controller方法如下所示:

public void Post([FromBody]string value)
{
    //But Value is NULL!!!!!!
}
Run Code Online (Sandbox Code Playgroud)

以下是我从Chrome中删除的请求标题中的一些值(我认为可能很有趣:

  • 请求方法:POST
  • 状态代码:204无内容
  • 接受:application/json,text/plain,/
  • 内容类型:application/x-www-form-urlencoded
  • X-Requested-With:XMLHttpRequest
  • 表单Dataview sourceview URL编码
  • 价值:foobar
  • 服务器:Microsoft-IIS/8.0
  • X-AspNet-Version:4.0.30319

我错过了什么?

ajax http-post asp.net-web-api angularjs

4
推荐指数
1
解决办法
3357
查看次数

标签 统计

angularjs ×2

ajax ×1

asp.net-web-api ×1

http-post ×1