1>首先:这是Getter and setter 方法的使用。 // get the current path $location.path();
// change the path $location.path('/newValue') 也可以变形使用啦~ //Change multiple segments in one go, chain setters like this:
$location.path('/newValue').search({key: value}); 2>Replace method(中文可能翻译成替代方法) 即,把原来的位置替换成别的 $location.path('/someNewPath'); $location.replace(); // or you can chain these as: $location.path('/someNewPath').replace(); 3>对比window.location(必须有图有真相是吧,上图)
。。。。我懒得翻译了术语太多。。总之功能很强就对了。 4>什么时候需要用到$ location呐?
Any time your application needs to react to a change in the current URL or if you want to change the current URL in the browser.
1>首先:这是Getter and setter 方法的使用。 // get the current path $location.path();
// change the path $location.path('/newValue')
也可以变形使用啦~ //Change multiple segments in one go, chain setters like this:
$location.path('/newValue').search({key: value});
2>Replace method(中文可能翻译成替代方法) 即,把原来的位置替换成别的 $location.path('/someNewPath'); $location.replace(); // or you can chain these as: $location.path('/someNewPath').replace();
3>对比window.location(必须有图有真相是吧,上图)
。。。。我懒得翻译了术语太多。。总之功能很强就对了。 4>什么时候需要用到$ location呐? Any time your application needs to react to a change in the current URL or if you want to change the current URL in the browser.