总共遇到2个问题,
1.$browser.$$checkUrlChange is not a function
2.Cannot read property 'url' of undefined
<script>
var app=angular.module('app',[])
.controller('test',function($scope){
$scope.cls_a="show";
$scope.cls_b="hide";
$scope.rdo_click=function(c)
{
if(!c)
{
$scope.cls_a="show";
$scope.cls_b="hide";
}
else
{
$scope.cls_a="hide";
$scope.cls_b="show";
}
}
});
function test_hashbang($scope,$location){
$scope.$location=$location;
};
function test_html5($scope,$location){
$scope.$location=$location;
};
function Brow(initUrl,baseHref)
{
this.onUrlChange=function(fn){
this.urlChange=fn;
};
this.url=function(){
return initUrl;
};
this.baseHref=function(){
return baseHref;
};
};
var Brows={
html5:new Brow('http://www.rttop.cn/a/c?a=b#hash','/a/index.html'),
hashbang:new Brow('http://www.rttop.cn/a/index.html#!/c?a=b#hash')
};
function createBrow(name){
var root=angular.element(document.getElementById(name));
console.log(root);
angular.bootstrap(root,[
function($compileProvider,$locationProvider,$provide){
$locationProvider.html5Mode(true).hashPrefix('!');
$provide.value('$browser',Brows[name]);
$provide.value('$document',root);
$provide.value('$sniffer',{
history:name=='html5'
});
$compileProvider.directive('tsBrowBar',function(){
return function(scope,elm,attrs){
var bs=Brows[attrs];
var input=angular.element('<input type="text" /').val(bs.url());
bs.url=function(url){
return input.val(url);
};
elm.append(input)
}
})
}
])
}
createBrow('html5');
createBrow('hashbang');
</script>
报错如下:
angular.js:13550 TypeError: Cannot read property 'url' of undefined
at http://localhost:8080/Angular/demo_02/demo_15.html:93:86
at invokeLinkFn (http://localhost:8080/Angular/js/angular-1.5.5/angular.js:9694:9)
at nodeLinkFn (http://localhost:8080/Angular/js/angular-1.5.5/angular.js:9093:11)
at compositeLinkFn (http://localhost:8080/Angular/js/angular-1.5.5/angular.js:8397:13)
at nodeLinkFn (http://localhost:8080/Angular/js/angular-1.5.5/angular.js:9088:24)
at compositeLinkFn (http://localhost:8080/Angular/js/angular-1.5.5/angular.js:8397:13)
at publicLinkFn (http://localhost:8080/Angular/js/angular-1.5.5/angular.js:8277:30)
at http://localhost:8080/Angular/js/angular-1.5.5/angular.js:1751:27
at Scope.$eval (http://localhost:8080/Angular/js/angular-1.5.5/angular.js:17229:28)
at Scope.$apply (http://localhost:8080/Angular/js/angular-1.5.5/angular.js:17329:25) <div ts-brow-bar="" bs="html5" class="brow">(anonymous function) @ angular.js:13550(anonymous function) @ angular.js:10225invokeLinkFn @ angular.js:9696nodeLinkFn @ angular.js:9093compositeLinkFn @ angular.js:8397nodeLinkFn @ angular.js:9088compositeLinkFn @ angular.js:8397publicLinkFn @ angular.js:8277(anonymous function) @ angular.js:1751Scope.$eval @ angular.js:17229Scope.$apply @ angular.js:17329bootstrapApply @ angular.js:1749invoke @ angular.js:4665doBootstrap @ angular.js:1747bootstrap @ angular.js:1767createBrow @ demo_15.html:81(anonymous function) @ demo_15.html:103
angular.js:13550 TypeError: $browser.$$checkUrlChange is not a function
at Scope.$digest (angular.js:17027)
at Scope.$apply (angular.js:17337)
at bootstrapApply (angular.js:1749)
at Object.invoke (angular.js:4665)
at doBootstrap (angular.js:1747)
at Object.bootstrap (angular.js:1767)
at createBrow (demo_15.html:81)
at demo_15.html:103(anonymous function) @ angular.js:13550(anonymous function) @ angular.js:10225Scope.$apply @ angular.js:17339bootstrapApply @ angular.js:1749invoke @ angular.js:4665doBootstrap @ angular.js:1747bootstrap @ angular.js:1767createBrow @ demo_15.html:81(anonymous function) @ demo_15.html:103
angular.js:17027 Uncaught TypeError: $browser.$$checkUrlChange is not a function