2014-01-20 67 views
0

我正在使用Angular-app作爲我的項目的種子應用程序。我寫了不少頁面,一切看起來都很好。控制器中未定義的作用域變量

但是在這裏我的模板看起來像這樣的情況之一:

<div ng-switch on="result"> 
    <div ng-switch="error">Something went wrong!, try later</div> 

     <div ng-switch-default> 
      Wait loading information!!!! 
     </div> 

     <div ng-switch-when="ok"> 
      <form ng-submit="sendData()"> 
       <input type="text" ng-model="myName"/ > 
       <button type="submit" >Create entry</button> 
      </form> 
     </div> 
</div> 

即使我鍵入myName我得到一個未定義的任何有價值的東西,當我提交表單?

爲什麼範圍迷路了?

是因爲ng-switch?我試着把ng-controller="MyController"放在

<div ng-switch-when="ok" ng-controller="MyController">....</div> 

它工作得很好!

雖然如果我嘗試使用更大的div一切之上,範圍再次

回答

1

未定義如果您正在使用NG-開關在運行時創建視圖和範圍迷路。爲了保存引用,你必須使用javascript引用對象。 工作的例子就是在這裏http://jsfiddle.net/J5ez6/ 因此你的看法會

<form ng-submit="sendData()"> 
       <input type="text" ng-model="mod.myName"/ > 
       <button type="submit" >Create entry</button> 
      </form> 
+0

由於一噸。這工作完美 –

相關問題