这可能是一个愚蠢的问题,但...... 是否可以在不使用$ watch的情况下将输入链接到$ location.search()? 我的意思是
这将是html提取
<input type="text" ng-model="vm.search.text"/>
这个控制器(在路由器中使用controllerAs)
this.search = $location.search()
我想在不使用$ watch的情况下将搜索结果反映在搜索字符串中,所以类似于https://url.blah.blah?text=
这是因为我讨厌使用手表,我想让我的控制器尽可能地保持苗条(应用程序非常大,我有点像这个想法)
我知道我可能只是建立一个指令并闭嘴,但这听起来对我来说太复杂了。
如果它没有意义,请告诉我。)
谢谢!
答案 0 :(得分:1)
你可以试试这个,在你的控制器中这样做:
.controller('testCtr', function($location){
this.search = {
text:'',
fn: $location.search.bind($location, 'text');
};
})
然后在你看来这样做:
<div ng-controller="testCtr as vm">
<input type="text" ng-model="vm.search.text" ng-change="vm.search.fn(vm.search.text)"/>
</div>