george tsubota

自分に自信を持て!ー>オレ

ng-switch内のng-modelの値はhg-switchの外にあるng-controllerでは取得できません。

<div ng-controller="ctrl">
	<select name="selectedQuestion" 
		ng-model="question_selected" 
		ng-options="item.name for item in select_items"></select>
	<hr/>
	<div ng-switch on="question_selected.key">
		<div ng-switch-when="single">
			<p><input type="text" ng-model="text_title" placeholder="タイトルを入力してください。"/></p>
			<p><input type="text" ng-model="text_note" placeholder="補足説明を入力してください。"/></p>
			<div ng-controller="single_ctrl">
				<h3>{{text_title}}</h3>
				<p>* {{text_note}}</p>
				<p ng-repeat="single_option in single_options">
					<input type="radio">{{single_option.text}}
				</p>
				<form ng-submit="add_single()">
					<input type="text" ng-model="single_options_text"/>
					<input type="submit" value="add"/>
				</form>
			</div>
		</div>
         </div>
</div>

上記はng-switchでselectで選択された値によって表示される内容が変更されます。
1行目の

タグで書かれたng-controllerのみでは、
のsubmitがキックされてもng-model="single_options_text"の値はadd_single()のファンクション内では取得できませんでした。
したがって、入れ子になる
で囲むと取得できました。