Javascript 安格拉斯赢得';除非刷新,否则无法运行控制器
非常简单(代码如下)。我有两个html页面,test.htm和ang.htm。我从test.htm开始,只需一个指向ang.htm页面的超链接。ang.htm包含angular js,它有一个简单的控制器来执行Hello World。我单击超链接导航到ang.htm。但是,我需要刷新ang.htm页面才能运行angular代码。为什么呢 test.htmJavascript 安格拉斯赢得';除非刷新,否则无法运行控制器,javascript,angularjs,Javascript,Angularjs,非常简单(代码如下)。我有两个html页面,test.htm和ang.htm。我从test.htm开始,只需一个指向ang.htm页面的超链接。ang.htm包含angular js,它有一个简单的控制器来执行Hello World。我单击超链接导航到ang.htm。但是,我需要刷新ang.htm页面才能运行angular代码。为什么呢 test.htm ang.htm {{你好}} 角度模块(“testApp”,[]); 角度模块(“testApp”).控制器(“testControll
ang.htm
{{你好}}
角度模块(“testApp”,[]);
角度模块(“testApp”).控制器(“testController”),功能($scope)
{
$scope.hello=“hello world”;
});
你的代码有效,小提琴在说话:
{{hello}
标记可能不会在页面显示加载后立即被替换,但仅此而已。导航到ang.htm
不会有问题
请注意,我在小提琴中复制/粘贴了您的ang.htm
内容:
<body ng-app="testApp" ng-controller="testController">
{{hello}}
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js"></script>
<script>
angular.module("testApp", []);
angular.module( "testApp" ).controller( "testController", function( $scope )
{
$scope.hello = "Hello world";
});
</script>
</body>
{{你好}}
角度模块(“testApp”,[]);
角度模块(“testApp”).控制器(“testController”),功能($scope)
{
$scope.hello=“hello world”;
});
你的代码有效,小提琴在说话:
{{hello}
标记可能不会在页面显示加载后立即被替换,但仅此而已。导航到ang.htm
不会有问题
请注意,我在小提琴中复制/粘贴了您的ang.htm
内容:
<body ng-app="testApp" ng-controller="testController">
{{hello}}
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js"></script>
<script>
angular.module("testApp", []);
angular.module( "testApp" ).controller( "testController", function( $scope )
{
$scope.hello = "Hello world";
});
</script>
</body>
{{你好}}
角度模块(“testApp”,[]);
角度模块(“testApp”).控制器(“testController”),功能($scope)
{
$scope.hello=“hello world”;
});
你的代码有效,小提琴在说话:
{{hello}
标记可能不会在页面显示加载后立即被替换,但仅此而已。导航到ang.htm
不会有问题
请注意,我在小提琴中复制/粘贴了您的ang.htm
内容:
<body ng-app="testApp" ng-controller="testController">
{{hello}}
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js"></script>
<script>
angular.module("testApp", []);
angular.module( "testApp" ).controller( "testController", function( $scope )
{
$scope.hello = "Hello world";
});
</script>
</body>
{{你好}}
角度模块(“testApp”,[]);
角度模块(“testApp”).控制器(“testController”),功能($scope)
{
$scope.hello=“hello world”;
});
你的代码有效,小提琴在说话:
{{hello}
标记可能不会在页面显示加载后立即被替换,但仅此而已。导航到ang.htm
不会有问题
请注意,我在小提琴中复制/粘贴了您的ang.htm
内容:
<body ng-app="testApp" ng-controller="testController">
{{hello}}
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js"></script>
<script>
angular.module("testApp", []);
angular.module( "testApp" ).controller( "testController", function( $scope )
{
$scope.hello = "Hello world";
});
</script>
</body>
{{你好}}
角度模块(“testApp”,[]);
角度模块(“testApp”).控制器(“testController”),功能($scope)
{
$scope.hello=“hello world”;
});
根据文件结构,我只将中的localhost/ang.htm更改为/ang.htm。它按预期工作
在您的情况下,使用Firebug进行调试将非常有用
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<a href="/ang.htm">Click</a>
</body>
</html>
根据文件结构,我只将中的localhost/ang.htm更改为/ang.htm。它按预期工作
在您的情况下,使用Firebug进行调试将非常有用
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<a href="/ang.htm">Click</a>
</body>
</html>
根据文件结构,我只将中的localhost/ang.htm更改为/ang.htm。它按预期工作
在您的情况下,使用Firebug进行调试将非常有用
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<a href="/ang.htm">Click</a>
</body>
</html>
根据文件结构,我只将中的localhost/ang.htm更改为/ang.htm。它按预期工作
在您的情况下,使用Firebug进行调试将非常有用
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<a href="/ang.htm">Click</a>
</body>
</html>
是的,它很有效。顺便说一句,最好将脚本移动到head。将脚本移动到head也不起作用。谢谢你的建议。是的,很有效。顺便说一句,最好将脚本移动到head。将脚本移动到head也不起作用。谢谢你的建议。是的,很有效。顺便说一句,最好将脚本移动到head。将脚本移动到head也不起作用。谢谢你的建议。是的,很有效。顺便说一句,最好将脚本移动到head。将脚本移动到head也不起作用。谢谢你的建议。它在JSFIDLE中确实有效,因为你在一个新的浏览器选项卡中。由于某些奇怪的原因导航时,停留在同一浏览器选项卡内不允许angular正确引导。我尝试过手动引导,但也失败了。神秘。你发布的代码是正确的。但是,如果您没有,也许您可以向我们提供整个ang.htm
文件的内容。但在本例中,它不能在JSFIDLE中重复,因为它涉及两个htm文件。只要把这两个文件放到你的web服务器上,试着运行它们,你就会明白我在说什么了。我只能猜测angular没有运行是因为angular没有处理导航事件,因此它没有尝试运行范围摘要之类的东西。它确实在JSFIDLE中工作,因为您在一个新的浏览器选项卡中。由于某些奇怪的原因导航时,停留在同一浏览器选项卡内不允许angular正确引导。我尝试过手动引导,但也失败了。神秘。你发布的代码是正确的。但是,如果您没有,也许您可以向我们提供整个ang.htm
文件的内容。但在本例中,它不能在JSFIDLE中重复,因为它涉及两个htm文件。只要把这两个文件放到你的web服务器上,试着运行它们,你就会明白我在说什么了。我只能猜测angular没有运行是因为angular没有处理导航事件,因此它没有尝试运行范围摘要之类的东西。它确实在JSFIDLE中工作,因为您在一个新的浏览器选项卡中。由于某些奇怪的原因导航时,停留在同一浏览器选项卡内不允许angular正确引导。