如何从隐藏的输入元素向角度服务传递值
本文关键字:服务 元素 隐藏 输入 | 更新日期: 2023-09-27 18:28:28
我用angularjs构建了一个服务,但使用jQuery DOM选择器从隐藏输入中查找2个值。。这有一股味道,我想知道是否有一种非jQuery的方法可以实现这一点。添加$scope似乎是错误的。
app.factory('ignoredPropertiesService', ['$http', function ($http) {
var sessionId = $('input[name=SessionGuid]').val();
var contactId = $('input[name=ContactId]').val();
var ignoredPropertiesService = {};
ignoredPropertiesService.getIgnoredProperties = function () {
return $http.get("/Contact/IgnoredProperties?sessionGuid=" + sessionId + "&contactId=" + contactId);
};
ignoredPropertiesService.resfreshIgnoredProperties = function () {
return $http.get('/Contact/RefreshIgnoredProperties?sessionGuid=' + sessionId + '&contactId=' + contactId);
};
return ignoredPropertiesService;
}]);
我应该用ng模型来装饰输入吗?
谢谢,Stephen
将ng-model
添加到隐藏输入将不起作用;Angular不会使用输入值更新模型。不过,你可以试试这个:
<input type="hidden" value="{{ value }}" ng-init="value = 'foobar'">
您也可以编写自定义指令来执行此操作。