2016-12-16 26 views
1

我想运行此程序,我看不到输出。你可以让我知道我在这里失踪了什么。提前致谢。问题与角度分离的示波器

<html> 
<head ng-app="myApp"> 
<title>Test</title> 

<link rel="stylesheet" href="//cdn.jsdelivr.net/foundation/4.3.2/css/foundation.min.css"> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js"></script> 

</head> 
<body> 
<div my-directive my-url="http://www.google.com" my-click="Click me"> 

</div> 
</body> 
<script> 
angular.module('myApp',[]).directive('myDirective',function() 
{ 
    return 
    { 
     restrict : 'AE', 
     replace : true, 
     scope : 
     { 
      myURL :'@', 
      myClick : '@' 
     }, 
     template : '<a href="{{myURL}}">{{myLinkText}}</a>' 
    }; 
}); 
</script> 
</html> 
+0

我做了免费的代码错误,但还是我看不到在输出任何东西....我可以知道预期输出..... HTTP://plnkr.co/edit/auTH8bStpHrX7r8xUJbI P =预览.. ...希望有人能帮到这个 –

+0

谢谢。您没有看到“点击我”按钮,因为模板定义是错误的。请修改代码的模板部分,并将“Click Me”作为输出。期望的是它应该重定向到google.com点击它,对吧?不知道我是否缺少任何模板:'{{myClick}}' – ang123

+0

在以前的版本中,指令已经发生了很大变化,特别是在隔离区范围内。你正在使用一个相当老的AngularJS版本。你有可能升级到1.5甚至1.4吗? – Toddsden

回答

2

它看起来像你把你的Angular应用程序的根放在标题中而不是在正文中。 从头部更改ng-app="myApp"属性的位置到身体HTML元素

<html ng-app="myApp"> <!-- new location --> 
<head > <!-- ng-app="myApp" it was here --> 
    <title>Test</title> 

    <link rel="stylesheet" href="//cdn.jsdelivr.net/foundation/4.3.2/css/foundation.min.css"> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js"></script> 

</head> 

指令{{myLinkText}}不存在,它应该改名为{{myClick}}

+0

感谢您的更正。它仍然没有工作。我得到一个空白页面。 – ang123

+0

我在浏览器控制台中看到以下几个错误:isolatedscopes2.html:22未捕获的SyntaxError:意外的令牌: angular.js:78未捕获的错误:[$ injector:modulerr]由于: 错误: $ injector:nomod]模块'myApp'不可用!您拼错了模块名称或忘记加载模块名称。如果注册模块确保您指定依赖关系作为第二个参数。 – ang123

1

一些如何通过花一整天我能够显示文本,并能够点击它,但没有重定向到提到的URL,我在控制台中出现错误,如Refused to display 'https://www.google.co.in/?gfe_rd=cr&ei=kepTWNDiIvLI8Afnp4HIBg' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.,你可以找到相同的here in console

+0

感谢您的更新。有关解决控制台错误的任何想法以及如何使其工作? – ang123

+0

不幸的是,我也不知道并等待有人知道这件事 –