1
我有以下HTML结构:angularjs嵌套控制器 - 形式不确定
<body ng-controller="checkoutController">
<div class="main clearfix" ng-controller="abroadCourseController">
//html useless information
<form name="checkout_form" ng-submit="submitForm()" novalidate>
<div validate-section="checkoutInfo" ng-show="stepOne">
//fields
<div class="confirmationBox">
<button type="button" ng-click="displayPaymentMethods()">SHOW PAYMENT METHODS</button>
</div>
</div>
<div validate-section="paymentAbroadCourseB2C" ng-show="stepTwo" >
//fields
<div class="confirmationBox">
<button type="button" ng-click="submitForm()">FINISH</button>
</div>
</div>
</form>
</div>
</body>
及以下JS:
var myApp = angular.module('myApp',[]);
myApp.controller('checkoutController', function ($scope) {
$scope.submitForm = function(){
$scope.stepOne = true;
$scope.stepTwo = false;
alert($scope.checkout_form);
alert('oi');
};
});
myApp.controller('abroadCourseController', function ($scope) {
$scope.stepOne = true;
$scope.stepTwo = false;
$scope.displayPaymentMethods = function(){
$scope.stepOne = false;
$scope.stepTwo = true;
alert($scope.checkout_form);
alert('oi');
};
});
基本上是我需要的是有通过父控制器上checkout_form访问,但是,它是未定义的。有没有办法实现这一点?
这里有一个的jsfiddle:http://jsfiddle.net/thm259o7/
可以使用$ rootScope为 –
你说是父控制器上未定义 - 孩子控制器呢?它也没有定义吗? PS不使用警报,因为它会冻结线程并导致大量问题,请改用console.log。实际上使用警报可能是你的问题 – danday74
@ danday74 console.log在jsfiddle –