In my app I'm trying to pass to mvc controller parameters to angular controller. because i want to get data from another api.
MVC Controller
public ActionResult Hotel(long hotelCode, string Destination)
{ return View(model); }
In view i pass model to script. so i can get parameters to angular.
VIEW
<script type="text/javascript">
var data = @Html.Raw(Json.Encode(Model));</script>
AngulerJS Controller
app.controller('ctrl', function ($scope, $q, $window, studentService, filterFilter) {
$scope.datax = $window.data;
$scope.saveSubs = function () {
var sub = {
Des: $scope.datax.HotelCode,
DepartureDate: $scope.datax.Des
};
var saveSubs = APIService.hotelavailability(sub);
saveSubs.then(function (d) {
console.log("Succss");
$scope.respData = d.data.hotels;
}, function (error) {
console.log('Oops! Something went wrong while saving the data.');
alert("Oops! Something went wrong while saving the data.");
});
};
});
Is their any way to call api and bind data to view without passing parameter to angular controller?.
ng-initto set or intialize your data to ng controllerctrland split your code among multiple modules, components, directives, filters, ...