Currently, I am utilizing the ionic framework in an attempt to send a request to a service. However, I am facing difficulties when it comes to passing parameters to the function.
The structure of my HTML (ionic design) is outlined below:
<ion-view view-title="Service Factor" ng-controller="beamdeflectionCtrl">
<ion-content>
<div class="item">
<form novalidate class="col-lg-2">
<div class="list">
<label class="item item-input item-stacked-label">
<span class="input-label">Shaft Length</span>
<input type="number" name="itsShaftLength" placeholder="1212" ng-model="itsShaftLength">
</label>
<label class="item item-input item-stacked-label">
<span class="input-label">Running Load</span>
<input type="number" placeholder="1212" ng-model="itsRunningLoad">
</label>
<label class="item item-input item-stacked-label">
<span class="input-label">Area Moment Of Inertia</span>
<input type="number" placeholder="1212"
ng-model="itsAreaMomentOfInertia">
</label>
<label class="item item-input item-stacked-label">
<span class="input-label">Modulus Of Elasticity</span>
<input type="number" placeholder="1212"
ng-model="itsModulusOfElasticity">
</label>
</div>
<div class="form-group">
<button class="btn btn-success btn-lg" ng-click="post()">Get Beam Defection</button>
</div>
</form>
</div>
</ion-content>
</ion-view>
Additionally, here is my Javascript file:
angular.module('beamdeflection', [])
.controller('beamdeflectionCtrl', beamdeflectionCtrl,['$scope']);
function beamdeflectionCtrl($stateParams, $scope, $http, $ionicPopup) {
$scope.post = function () {
$http({
url: "/myurl",
method: "GET",
params: {
shaftLength: $scope.itsShaftLength,//I am not getting this value
runningLoad:$scope.itsRunningLoad,//I am not getting this value
areaMomentOfInertia: $scope.itsAreaMomentOfInertia,//I am not getting this value
modulusOfElasticity:$scope.itsModulusOfElasticity//I am not getting this value
}}).success(function (data, status, headers, config) {
$ionicPopup.alert({
title: 'Beam Deflection Calculated',
template: data
});
$scope.data = data;
}).error(function (data, status, headers, config) {
$ionicPopup.alert({
title: 'Beam Deflection Failed',
template: data
});
});
};
};
}
Regrettably, within the post function, $scope.itsShaftLength
and other parameters are returning undefined values according to the debugger. As a newcomer to angular, I am left pondering if there is something crucial that I may have overlooked in my code. Furthermore, in an attempt to pass $scope to the function as
$scope.post = function ($scope){....
, an error was triggered stating "$scope not defined". Any assistance provided would be greatly appreciated.