我有我的頁面元素像這樣如何將數據從AngularJS控制器發送到其服務?
<div ng-app="myApp" class="ng-cloak" ng-controller="MyController as ctrl">
<div class="item" ng-repeat="i in ctrl.items">
<h3>Some text...</h3>
<p ng-bind="i.id"></p>
<button ng-click="alertValue(i.id)">DETAILS</button></p>
</div>
</div>
我的控制器看起來是這樣的,有一個方法
'use strict';
App.controller('MyController', ['$scope', 'Item', function ($scope, Item) {
$scope.alertValue = function (id) {
alert('clicked:' + id);
}
}
的正常工作,我得到id爲警報。但是,我如何將這個ID從控制器發送到我的服務?我嘗試了幾個教程,但他們都不一樣,我完全迷失了。任何人都可以用簡單的方式向我解釋這一點,並展示如何做到這一點? 可能需要提供一些其他信息?謝謝。
最好去通過文檔https://docs.angularjs.org/guide/services –
我會的,但我希望得到一些簡單的例子也是如此。 Thanx先生,Mr_Perfect。很好的登錄btw。 – Bobby
你的服務是什麼?項目? –