아래 angularjs에서 팩토리 mathod를 사용하여 한 컨트롤러에서 다른 컨트롤러로 함수를 호출하고 싶습니다.
var Inciapp = angular.module('IncidentApp', []);
Inciapp.controller('GetAlphabetical', function ($scope, CustomerFactory) {
$scope.Customer = null;
CustomerFactory.getCustomers().then(function (successResponse) {
$scope.Customer = successResponse.data; // please check the request response if list id in data object
}, function (errorResponse) {
throw error;
})
});
Inciapp.factory('CustomerFactory',function ($http) {
var _factory = {};
_factory.getCustomers = function () {
return $http.get('@Url.Content("~/Home/GetIncidentlist")');
};
return _factory;
});
HTML :
<div data-ng-app="IncidentApp">
<div data-ng-controller="GetAlphabetical">
<table>
<thead>
<tr>
<th>IncidentID</th>
</tr>
</thead>
<tfoot>
<tr ng-repeat="h in Customer">
<td>{{ h.Name }}</td>
</tr>
</tfoot>
</table>
</div>
</div>
<div data-ng-controller="GetAlphabeticalSecond">
<table>
<thead>
<tr>
<th>IncidentID</th>
</tr>
</thead>
<tfoot>
<tr ng-repeat="h in Customer">
<td>{{ h.Name }}</td>
</tr>
</tfoot>
</table>
</div>
씨# :
List<incident> lst = new List<incident>();
lst.Add(new incident { ID = "123", contact = "98765", IDcontact = "456", IDnumber = "7866", Name = "Nayeem", NameID = "3333", number = "987654321", Phone = "1234567890" });
lst.Add(new incident { ID = "123", contact = "98765", IDcontact = "456", IDnumber = "7866", Name = "Nayeem", NameID = "3333", number = "987654321", Phone = "1234567890" });
lst.Add(new incident { ID = "123", contact = "98765", IDcontact = "456", IDnumber = "7866", Name = "Nayeem", NameID = "3333", number = "987654321", Phone = "1234567890" });
lst.Add(new incident { ID = "123", contact = "98765", IDcontact = "456", IDnumber = "7866", Name = "Nayeem", NameID = "3333", number = "987654321", Phone = "1234567890" });
lst.Add(new incident { ID = "123", contact = "98765", IDcontact = "456", IDnumber = "7866", Name = "Nayeem", NameID = "3333", number = "987654321", Phone = "1234567890" });
lst.Add(new incident { ID = "123", contact = "98765", IDcontact = "456", IDnumber = "7866", Name = "Nayeem", NameID = "3333", number = "987654321", Phone = "1234567890" });
lst.Add(new incident { ID = "123", contact = "98765", IDcontact = "456", IDnumber = "7866", Name = "Nayeem", NameID = "3333", number = "987654321", Phone = "1234567890" });
lst.Add(new incident { ID = "123", contact = "98765", IDcontact = "456", IDnumber = "7866", Name = "Nayeem", NameID = "3333", number = "987654321", Phone = "1234567890" });
lst.Add(new incident { ID = "123", contact = "98765", IDcontact = "456", IDnumber = "7866", Name = "Nayeem", NameID = "3333", number = "987654321", Phone = "1234567890" });
return Json(lst, JsonRequestBehavior.AllowGet);
업데이트 된보기 파일
<div data-ng-app="IncidentApp">
<!-- angular IncidentApp scope starts from here -->
<div data-ng-controller="GetAlphabetical">
<table>
<thead>
<tr>
<th>IncidentID</th>
</tr>
</thead>
<tfoot>
<tr ng-repeat="h in Customer">
<td>{{ h.Name }}</td>
</tr>
</tfoot>
</table>
</div>
<div data-ng-controller="GetAlphabeticalSecond">
<table>
<thead>
<tr>
<th>IncidentID</th>
</tr>
</thead>
<tfoot>
<tr ng-repeat="h in Customer">
<td>{{ h.Name }}</td>
</tr>
</tfoot>
</table>
</div>
<!-- angular IncidentApp scope ends from here -->
</div>
Angular는 응용 프로그램 범위에 포함되는 경우에만 작동합니다. 귀하의 경우 GetAlphabetical은 응용 프로그램 범위에 있지만 두 번째 컨트롤러는 범위를 벗어났습니다. 문제를 해결하기 위해 HTML보기를 업데이트했습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다