我有一个关于如何将输入值绑定到对象的问题? 打字稿-文件:
function testProcedure() {
var cookies = WL.Server.getClientRequest().getCookies();
cookies.forEach(function(cookie){
var name = cookie.getName(),
value = cookie.getValue();
if(name == 'myCookie') {
// read/update cookie info
}
// Cookie Object
// http://docs.oracle.com/javaee/7/api/javax/servlet/http/Cookie.html
});
return {
cookies: cookies.length
};
}
,html看起来像
private shareholder = {
shares : 'value from input'
name: 'value from input'
}
答案 0 :(得分:0)
假设shareholder
是'myController'上的对象,请执行以下操作:
<div ng-controller="myController as $ctrl">
<input name="shares" ng-model="$ctrl.shareholder.shares" type="number" required />
<input name="name" ng-model="$ctrl.shareholder.name" required />
</div>
此外,由于您访问控制器外部的数据,请制作shareholder
对象public
。
如果您使用普通的$scope
,则可以执行以下操作:
$scope.shareholder = {
shares: 'value from input'
name: 'value from input'
}
视图:
<input name="shares" ng-model="shareholder.shares" type="number" required />
<input name="name" ng-model="shareholder.name" required />
答案 1 :(得分:0)
<强>控制器强>
var shareholder = {
shares : 'value from input'
name: 'value from input'
}
<强> HTML 强>
<input name="shares" ng-model="shareholder.shares" type="number" required>
<input name="name" ng-model="shareholder.name" required>