1

我已经用 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-model 装饰输入吗?

谢谢你,斯蒂芬

4

1 回答 1

1

添加ng-model到隐藏的输入将不起作用;Angular 不会使用输入值更新模型。不过,你可以试试这个:

<input type="hidden" value="{{ value }}" ng-init="value = 'foobar'">

你也可以编写一个自定义指令来做到这一点。

于 2013-08-21T05:29:00.467 回答