0
我正在使用ng-switch在佈局中創建一個過濾輸入字段。我打開路由名稱,並使用此字段在每個頁面上以ng-repeat過濾數據。佈局問題中的ng-switch元素
div(ng-controller="NavbarCtrl", ng-switch on="route.current.name")
input.filter(ng-switch-when='offers',type="text", ng-model="$parent.$parent.search.title")
input.filter(ng-switch-when='merchants',type="text", ng-model="$parent.$parent.search.name")
這種方法的問題是,我在一個頁面上輸入導航到其他路徑和過濾器數據時,其他頁面上也一直保存價值。我正在使用內置的角度搜索過濾器,因此模型名稱。
我可以以某種方式重置路由更改過濾器的值?
另一個問題是,我發現這個$ parent。$ parent作用域訪問不切實際,但我找不到更優雅的方式。
任何提示非常感謝!
如果您在父作用域中使用對象,則不應該使用'$ parent'。也就是說,如果在父範圍中定義了'$ scope.search = {...}',則子範圍(但不是指令隔離範圍)可以通過[普通JavaScript原型繼承]訪問此對象(http://stackoverflow.com /問題/ 14049480 /什麼 - 是最細微差別的範圍外,原型,原型繼承功能於angularjs)。 – 2013-03-18 16:22:06
'$ route.current.name'可能?? – 2013-03-18 16:25:25
在提供的路線我有一個數據表,這樣tr(ng-repeat =「o in offer | filter:search」)td {{offer.title}}等等。我無法通過ng- model ='search.title' – glasspill 2013-03-18 16:28:43