모두. 나는 이상한 문제가있다 ... 나는 내 애플 리케이션에 여러 주를 가지고, 그들은 모두 하나의 컨트롤러의 내부를 제외하고 작동하는 것 같습니다. 나는 그 기능을 내가 컨트롤러와 함께 사용하려고 공장 및 상태 및 기능 트리거하도록되어보기 게시 :
app.factory('handleShipping', ['$http', function($http){
var handleShipping = {};
handleShipping.validate = function(address){
return ($http.post('/shipping/validate',address).success(function(data){
console.log(JSON.stringify(data));
}));
}
return handleShipping;
}]);
을 ...
app.controller('ValidateCtrl',['$scope','$state', 'handleShipping','shipperName', 'auth',function($scope, $state, handleShipping, shipperName,auth){
$scope.getShipper = function(shipName){
shipperName.shipper = shipName;
};
$scope.validateAddress = function(){
handleShipping.validate($scope.user).error(function(error){
$scope.error = error;console.log('Error!');
}).then(function(){
$state.go('label');
});
};
}]);
...
.state('address', {
url: '/address',
templateUrl: '/address.html',
controller: 'ValidateCtrl'
})
.state('label', {
url: '/label',
templateUrl: '/label.html',
controller: 'LabelCtrl'
});
...
<script type="text/ng-template" id="/address.html">
<div class="page-header">
<h1>Address, please</h1>
</div>
<div ng-show="error" class="alert alert-danger row">
<span>{{ error.message }}</span>
</div>
<form ng-submit="validateAddress()"
style="margin-top:30px;">
<div class="form-group">
<input type="text" class="form-control" placeholder="Street"
ng-model="user.street"></input>
</div>
<div class="form-group">
<input type="text"
class="form-control"
placeholder="City"
ng-model="user.city"></input>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="State" ng-model="user.state"></input>
</div>
<div class="form-group">
<input type="text"
class="form-control"
placeholder="Zip Code"
ng-model="user.zipCode">
</input>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</script>
,536,
오류 메시지가 표시되지 않습니다. localhost : 3000/label을 입력하면보기를 볼 수 있습니다. 또한, 뭔가 이상한 점을 발견합니다 ... 내가보기 '주소'에 머물러 있고 '제출'버튼을 누르면 아무 일도 일어나지 않습니다. 혼자 페이지를 떠나, 앱이 단말기에서 실행되는 경우, 그것은 무작위로 콘솔에 오류 메시지가 표시되고 터미널에, 나는 어떤 도움을 크게 감상 할 수
POST /shipping/validate - - ms - -
볼 수 있습니다.
대단히 감사합니다! – thrasymachus
@thrasymachus 감사합니다 :-), 도와 줘서 고맙습니다. –