我是AngularJs的新手,我正在通过Angular文档来理解它。我最近遇到了这段代码$location.path() == '/a'
,但我不明白它的意思和作用。在此示例中,==
用作赋值运算符?所以有人能解释一下它会有什么不同吗?它是特定角度的还是Javascript中的含义。
it('should show example', inject(
function($locationProvider) {
$locationProvider.html5Mode(false);
$locationProvider.hashPrefix('!');
},
function($location) {
// open http://example.com/base/index.html#!/a
$location.absUrl() == 'http://example.com/base/index.html#!/a'
$location.path() == '/a'
$location.path('/foo')
$location.absUrl() == 'http://example.com/base/index.html#!/foo'
$location.search() == {}
$location.search({a: 'b', c: true});
$location.absUrl() == 'http://example.com/base/index.html#!/foo?a=b&c'
$location.path('/new').search('x=y');
$location.absUrl() == 'http://example.com/base/index.html#!/new?x=y'
}
));
整个代码为from the angular docs。
答案 0 :(得分:1)
如果您有网址http://example.com/base/index.html#!/a
,它会在hashBang模式下向您显示 $location.absUrl()
将为'http://example.com/base/index.html#!/a'
(即$location.absUrl() == 'http://example.com/base/index.html#!/a'
是true
)
与$location.path()
相同的将是'/a'
($location.path() == '/a'
是true
)