Javascript $scope未绑定Angular JS中的函数内部
我正在使用ionic框架,试图向服务发出请求,但无法将参数传递给函数 我的Html(离子结构)如下所示:Javascript $scope未绑定Angular JS中的函数内部,javascript,angularjs,ionic-framework,cross-platform,ionic,Javascript,Angularjs,Ionic Framework,Cross Platform,Ionic,我正在使用ionic框架,试图向服务发出请求,但无法将参数传递给函数 我的Html(离子结构)如下所示: <ion-view view-title="Service Factor" ng-controller="beamdeflectionCtrl"> <ion-content> <div class="item"> <form novalidate class="col-lg-2">
<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>
由于某些原因,
$scope.itsShaftLength
和post函数中的其他参数没有获取值。调试器声明它们未定义。我是个新手。我想知道我的代码是否遗漏了什么。此外,我尝试将$scope作为$scope.post=函数($scope){..
传递给函数,但它对我说“$scope not defined”。非常感谢您的帮助。如我在评论中所述,您应该始终在ng model
中使用对象,因为在子范围中会破坏原语的绑定
一般经验法则:在ng模型中始终有一个点
尝试将所有ng模型
更改为具有对象前缀和点
<input ng-model="formData.itsModulusOfElasticity">
这还简化了作为参数发送的内容,因为所有表单数据都已包含在一个对象中:
params: angular.copy($scope.formData) // using "copy" strips out any angular properties
从这里开始进一步阅读,确保阅读有关角度范围的内容
正如我在评论中提到的,您应该始终在
ng模型中使用对象,因为原语的绑定在子范围中被破坏
一般经验法则:在ng模型中始终有一个点
尝试将所有ng模型
更改为具有对象前缀和点
<input ng-model="formData.itsModulusOfElasticity">
这还简化了作为参数发送的内容,因为所有表单数据都已包含在一个对象中:
params: angular.copy($scope.formData) // using "copy" strips out any angular properties
从这里开始进一步阅读,确保阅读有关角度范围的内容
正如我在评论中提到的,您应该始终在ng模型中使用对象,因为原语的绑定在子范围中被破坏
一般经验法则:在ng模型中始终有一个点
尝试将所有ng模型
更改为具有对象前缀和点
<input ng-model="formData.itsModulusOfElasticity">
这还简化了作为参数发送的内容,因为所有表单数据都已包含在一个对象中:
params: angular.copy($scope.formData) // using "copy" strips out any angular properties
从这里开始进一步阅读,确保阅读有关角度范围的内容
正如我在评论中提到的,您应该始终在ng模型中使用对象,因为原语的绑定在子范围中被破坏
一般经验法则:在ng模型中始终有一个点
尝试将所有ng模型
更改为具有对象前缀和点
<input ng-model="formData.itsModulusOfElasticity">
这还简化了作为参数发送的内容,因为所有表单数据都已包含在一个对象中:
params: angular.copy($scope.formData) // using "copy" strips out any angular properties
从这里开始进一步阅读,确保阅读有关角度范围的内容
您确实没有在代码的$scope中定义ng模型。您可以这样做:
$scope.post = function (data) {
$http({
url: "/myurl",
method: "GET",
params: {
shaftLength: data.itsShaftLength,
runningLoad: data.itsRunningLoad,
areaMomentOfInertia: data.itsAreaMomentOfInertia,
modulusOfElasticity: data.itsModulusOfElasticity }})... more code...
在html中,您可以在所有输入端定义ng模型:
<input type="number" name="itsShaftLength" placeholder="1212" ng-model="data.itsShaftLength"> ...
您确实没有在代码的$scope中定义ng模型。您可以执行以下操作:
$scope.post = function (data) {
$http({
url: "/myurl",
method: "GET",
params: {
shaftLength: data.itsShaftLength,
runningLoad: data.itsRunningLoad,
areaMomentOfInertia: data.itsAreaMomentOfInertia,
modulusOfElasticity: data.itsModulusOfElasticity }})... more code...
在html中,您可以在所有输入端定义ng模型:
<input type="number" name="itsShaftLength" placeholder="1212" ng-model="data.itsShaftLength"> ...
您确实没有在代码的$scope中定义ng模型。您可以执行以下操作:
$scope.post = function (data) {
$http({
url: "/myurl",
method: "GET",
params: {
shaftLength: data.itsShaftLength,
runningLoad: data.itsRunningLoad,
areaMomentOfInertia: data.itsAreaMomentOfInertia,
modulusOfElasticity: data.itsModulusOfElasticity }})... more code...
在html中,您可以在所有输入端定义ng模型:
<input type="number" name="itsShaftLength" placeholder="1212" ng-model="data.itsShaftLength"> ...
您确实没有在代码的$scope中定义ng模型。您可以执行以下操作:
$scope.post = function (data) {
$http({
url: "/myurl",
method: "GET",
params: {
shaftLength: data.itsShaftLength,
runningLoad: data.itsRunningLoad,
areaMomentOfInertia: data.itsAreaMomentOfInertia,
modulusOfElasticity: data.itsModulusOfElasticity }})... more code...
在html中,您可以在所有输入端定义ng模型:
<input type="number" name="itsShaftLength" placeholder="1212" ng-model="data.itsShaftLength"> ...
好的,我有点困惑,成功函数中的数据应该包含您希望在ionic警报中显示的信息,对吗?第二件事我注意到,我认为您不能将返回数据传递给警报您只能使用带有字符串的模板和html文件或smth的templateUrl,因此id建议var string=data.something,然后传递绳子template@stackg91是的。但是,我没有给服务提供正确的数据(而是一堆未知数据),它正在爆炸。没有意义,$scope.post
正在发出GET请求不确定这是否是原因,但您的输入字段不需要“name”?我发现并不是所有的模型都有ITA,所以…总是在ng模型中使用dot
来利用继承。因为您使用的原语可能在子作用域中丢失,所以我有点困惑,成功函数中的数据应该包含希望在ionic alert中显示的信息,对吗?第二件事注意:我不认为您可以将返回数据传递给警报您只能使用带字符串的模板和html文件或smth的templateUrl,因此我建议var string=Data.something,然后在template@stackg91是的。但是,我没有给服务提供正确的数据(而是一堆未知的数据)它正在爆炸。没有意义,$scope.post
正在发出GET请求不确定这是否是原因,但您的输入字段不需要“name”?我发现并不是所有的模型都有ITA,所以…总是在ng模型中使用dot
来利用继承。因为您使用的原语可能在子作用域中丢失,所以我有点困惑,成功函数中的数据应该包含希望在ionic alert中显示的信息,对吗?第二件事注意:我不认为您可以将返回数据传递给警报您只能使用带字符串的模板和html文件或smth的templateUrl,因此我建议var string=Data.something,然后在template@stackg91是的。但是,我没有给服务提供正确的数据(而是一堆未知的数据)它正在爆炸。没有意义,$scope.post
正在发出GET请求不确定这是否是原因,但您的输入字段不需要“name”?我发现并不是所有的模型都有ITA,所以…总是在ng模型中使用dot
来利用继承。因为您使用的原语可能在子作用域中丢失,所以我有点困惑,成功函数中的数据应该包含希望在ionic alert中显示的信息,对吗?第二件事注意到我没有