【问题标题】:AngularJS - one of my directives don't work, the others do?AngularJS - 我的一个指令不起作用,其他的呢?
【发布时间】:2015-06-20 00:59:40
【问题描述】:

我最近一直在寻找工作,并决定建立一个网站作为一种简历,同时学习 AngularJS。我参加了 CodeSchools Angular 课程,并按照我的意愿慢慢构建了这个网站。 (请不要根据现在的样子来判断它,但想法是可以理解的)

现在是代码问题!

网站: http://danieboy.github.io/

Index.html(开始、恢复、审查和联系工作 - 我的项目不

<div class="content-wrap">
          <section id="section-shape-1">
            <start></start>
          </section>

          <section id="section-shape-2">
            <resume></resume>
          </section>

          <section id="section-shape-3">
            <myprojects></myprojects>
          </section>

          <section id="section-shape-4">
            <reviews></reviews>
          </section>

          <section id="section-shape-5">
            <contact></contact>
          </section>
        </div>

myDirectives.js

    var app = angular.module('blog-directives', []);

app.directive("start", function() {
    return {
        restrict: "E",
        templateUrl: "start.html"
    }
});

app.directive("resume", function() {
    return {
        restrict: "E",
        templateUrl: "resume.html"
    }
});

app.directive("myprojects", function() {
    return {
        restrict: "E",
        templateUrl: "myprojects.html"
    }
});

app.directive("reviews", function() {
    return {
        restrict: "E",
        templateUrl: "reviews.html"
    }
});

app.directive("contact", function() {
    return {
        restrict: "E",
        templateUrl: "contact.html"
    }
});

start.html (工作)

    <h1>
    <a id="welcome-to-my-developer-blog" class="anchor" href="#welcome-to-my-developer-blog" aria-hidden="true"><span class="octicon octicon-link"></span></a>Welcome to my developer blog!</h1>
*Text...*
<img src="images/Web-under-construction.jpeg" alt="Under Construction"></br>

myprojects.html (不工作)

<h3><a href="http://danieboy.github.io/hotorcold"> Hot or Cold</a></h3>
<h3><a href="http://danieboy.github.io/flatlander-store/index.html"> Flatlander Store Project</a></h3>
<h3><a href="http://danieboy.github.io/bmi-calculator/index.html"> Android Application: BMI-counter</a></h3>
<h3><a href="http://www.markettime.se/"> Markettime through Diflex AB (Swedish)</a></h3>
<h3><a href="http://test2.markettools.se"> Markettools through Diflex AB (Swedish)</a></h3>

我真的不知道为什么其中四个会起作用,而第五个却不行。

我一开始不小心创建了名为 MyProjects 而不是 myprojects 的文件并将其删除,但我可能错误地没有越过安全删除,因为我认为这没关系,因为我再次创建相同的文件.这会是个问题吗?在自动更新的 .idea/workspace.xml 文件中(我使用 WebStorm 10.1)

提前致谢:)

【问题讨论】:

  • 看起来不错,我相信你很快就会找到工作;)
  • 将 myprojects.html 更改为 myProjects.html xD
  • 这实际上是一个可行的解决方案......我真的不明白为什么。代码中没有任何地方写成 myProjects。它到处都写着 myprojects...

标签: javascript xml angularjs html


【解决方案1】:

它在 Chrome 控制台中显示以下堆栈跟踪:

Error: [$compile:tpload] Failed to load template: myprojects.html
http://errors.angularjs.org/1.2.15/$compile/tpload?p0=myprojects.html
    at angular.js:78
    at angular.js:6576
    at angular.js:7740
    at deferred.promise.then.wrappedErrback (angular.js:11109)
    at deferred.promise.then.wrappedErrback (angular.js:11109)
    at deferred.promise.then.wrappedErrback (angular.js:11109)
    at angular.js:11242
    at Scope.$get.Scope.$eval (angular.js:12175)
    at Scope.$get.Scope.$digest (angular.js:12004)
    at Scope.$get.Scope.$apply (angular.js:12279)

所以您可能只是放错了 myprojects.html。

当我导航到 http://danieboy.github.io/myprojects.html 时,它显示 404,所以这证实了这是问题所在。

【讨论】:

  • 正如您在评论中所说...将名称更改为 myProjects 有效。而且我不知道为什么,因为它在代码中被写为 myproject EVERYWHERE。不过谢谢你:)
  • 你……我在想,嘿,我没这么说!
  • 哈哈确实是个很迷的名字!
猜你喜欢
  • 2015-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-05
  • 1970-01-01
  • 2014-04-30
  • 1970-01-01
  • 2017-01-23
相关资源
最近更新 更多