我試圖從控制器的範圍獲取表單對象,當我得到一個名稱來形式。 它工作正常,但如果我用ng-switch創建表單,表單從不在範圍中顯示。與ng開關的角度形式
視圖
<body ng-controller="MainCtrl">
<div ng-switch on="type">
<form name="theForm" ng-switch-when="1">
<label>Form 1</label>
<input type="text"/>
</form>
<form name="theForm" ng-switch-when="2">
<label>Form 2</label>
<input type="text"/>
<input type="text"/>
</form>
</div>
<button ng-click="showScope()">Show scope</button>
</body>
控制器
app.controller('MainCtrl', function($scope) {
$scope.type = 1;
$scope.showScope = function(){
console.log($scope);
};
});
如果刪除了NG-開關我可以看到從$範圍爲形式obj中的屬性 「theForm」。
任何想法如何做到這一點。我不想擁有不同名稱的兩種表格並使用ng-show。
這裏是例如「不工作」 http://plnkr.co/edit/CnfLb6?p=preview
THX。花了一個小時。我得到的症狀是$ valid和$ dirty變得對我無效。 – ErichBSchulz 2014-12-20 12:01:30