我在我的应用程序中得到了这个angularJS:
<div data-ng-controller="GetCategory">
<div>
Välj Kategori:
<select data-ng-model="activities.header"
data-ng-options="a.header for a in activities"></select>
</div>
<p>{{ activities.header.header}}</p>
Vald Id: {{ activities.header.id}}
</div>
上面的代码会显示一个下拉菜单,选择的值最终会显示在:
<p>{{ activities.header.header}}</p>
我想要做的是将值保存在:
<p>{{ activities.header.header}}</p>
所以我可以将它与此一起传递:
$scope.save = function () {
$http({
method: 'POST',
url: '/Home/SaveListFromAngular',
headers: {
"Content-Type": "application/json"
},
data: { todos: $scope.todos, var x : "{{ activities.header.header}}"}
});
}
我试图说明我想在这里做什么:
data: { todos: $scope.todos, var x : "{{ activities.header.header}}"}
希望我对某人足够清楚。谢谢!
答案 0 :(得分:1)
看起来你需要做的就是对活动.header.header进行字符串化并发送它。所以,它看起来像这样......
$scope.save = function () {
var theHeader = JSON.stringify($scope.activities.header.header)
, theTodos = JSON.stringify($scope.todos);
$http({
method: 'POST',
url: '/Home/SaveListFromAngular',
headers: {
"Content-Type": "application/json"
},
data: { todos: theTodos , x : theHeader}
});
}