- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个 Angular-Promise,它调用一个 http 方法(对应于 REST 服务),该方法应该在使用 ng-submit 提交表单时调用。它永远不会发生,也没有错误,似乎该函数从未被调用。这是 JavaScript 代码:
myapp.factory('CardFactory', ['$http', function($http){
return{
cardService: function(hclass) {
return $http({
method: 'get',
url: UrlServices.baseUrl + 'http://localhost:8080//HSRestServices/hsrest/decks/getCards/' + hclass,
})
}
}
}])
myapp.controller('CardCtrl', ['$scope', 'CardFactory', function($scope, CardFactory ){
$scope.card = "Druid";
$scope.cardService = function() {
CardFactory.cardService($scope.card)
.then(function (response) {
$scope.status = response.status;
$scope.card = response.data;
console.log("Response: " + JSON.stringify({data: response.data}));
if (response.status == 200){
$scope.card = response.data;
} else {
console.log("Response: Something went wrong.");
}
}, function (response) {
console.log("Response: Something went wrong.");
})
};
}]);
和 html 代码:
<body ng-app="mainApp">
<div ng-controller="CardCtrl">
<form ng-submit="cardService()">
<input type="submit" value="Submit">
</form>
<p ng-model="card">{{card}}</p>
</div>
</body>
有什么想法吗?提前谢谢您。
最佳答案
如果您在应用程序上没有看到“Druid”一词,很可能您没有在应用程序中包含 angular.js 和 app.js。
如果你这样做了,它可能正在工作,但你没有正确定义 UrlServices,并且它找不到它。您可以检查浏览器控制台以获取更多详细信息。
否则它对我有用。看看这个jsfiddle:https://jsfiddle.net/j8o0ag4t/
在控制台中我看到:
Error: Can't find variable: UrlServices
cardService@ http://fiddle.jshell.net/j8o0ag4t/show/:50:29卡服务@ http://fiddle.jshell.net/j8o0ag4t/show/:62:28 http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js:160:97 http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js:177:84$eval@ http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js:100:328$申请@ http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js:101:110 http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js:177:71 http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js:27:19forEach@[ native 代码]p@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js:7:262c@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js:26:493
关于javascript - AngularJS - 从未使用 ng-submit 调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33329267/
背景 我最近在 merge 期间遇到了一个意外未 merge 的文档文件的问题。 无论出于何种原因,我搞砸了 merge 并有效地删除了文件(和其他几个文件),因为我忘记了它们的存在。 现在我想查看我
我在我的网站上使用旧的 mysql 版本和 php 版本 4。 我的表结构: | orders_status_history_id | orders_id | orders_status_id |
我是一名优秀的程序员,十分优秀!