Angular无法在初始页面加载时

时间:2016-03-30 14:01:06

标签: angularjs

我有一个Angular模块,无论出于何种原因,它都不会在初始页面加载时实例化,有时候会在刷新时随机实例化。只是为了让你知道angular.js没有加载到<head>标签内,因为我无法控制它,所以我必须在体内调用脚本(代码基本上放在CMS模板中)。

这是代码目前的样子,我将实际脚本放在<script>标签中,以消除可能因为任何原因而无法加载带有模块的js文件的可能性。

<script src="/bizcontent/minuteclinic/desktop/general/angular.js"></script>
<script>
var app = angular.module('exampleApp', []);
  app.controller('MainCtrl', function($scope) {
    $scope.field = {
      value: null
    };
    $scope.field2 = {
      value2: null
    };
    $scope.field3 = {
      value3: null
    };
    $scope.field4 = {
      value4: null
    };
    $scope.field5 = {
      value5: null
    };
    $scope.field6 = {
      value6: null
    };
    $scope.field7 = {
      value7: null
    };
    $scope.field8 = {
      value8: null
    };
    $scope.field9 = {
      value9: null
    };
    $scope.field10 = {
      value10: null
    };

    $scope.question = {
      answers: [
        {title: "A (correct)",   correct: true, answer: "This is the correct answer"},
        {title: "B (incorrect)", correct: false, answer: "This is the incorrect answer"}
      ],
      answers2: [
        {title: "C (correct)",   correct: true, answer: "This is the correct answer"},
        {title: "D (incorrect)", correct: false, answer: "This is the incorrect answer"}
      ],
      answers3: [
        {title: "E (correct)",   correct: true, answer: "This is the incorrect answer"},
        {title: "F (incorrect)", correct: false, answer: "Pollen is #1"}
      ],
      answers4: [
        {title: "G (correct)",   correct: true, answer: "This is the correct answer"},
        {title: "H (incorrect)", correct: false, answer: "This is the incorrect answer"}
      ],
      answers5: [
        {title: "I (correct)",   correct: true, answer: "This is the correct answer"},
        {title: "J (incorrect)", correct: false, answer: "This is the incorrect answer"}
      ],
      answers6: [
        {title: "I (correct)",   correct: true, answer: "This is the correct answer"},
        {title: "J (incorrect)", correct: false, answer: "This is the incorrect answer"}
      ],
      answers7: [
        {title: "I (correct)",   correct: true, answer: "This is the correct answer"},
        {title: "J (incorrect)", correct: false, answer: "This is the incorrect answer"}
      ],
      answers8: [
        {title: "I (correct)",   correct: true, answer: "This is the incorrect answer"},
        {title: "J (incorrect)", correct: false, answer: "Yes, they are."}
      ],
      answers9: [
        {title: "I (correct)",   correct: true, answer: "This is the correct answer"},
        {title: "J (incorrect)", correct: false, answer: "This is the incorrect answer"}
      ],
      answers10: [
        {title: "I (correct)",   correct: true, answer: "This is the incorrect answer"},
        {title: "J (incorrect)", correct: false, answer: "Hay fever sufferers should know the pollen count forcast before planning any outdoor activities."}
      ]
    };
    $scope.select = function(field, answer) {
      if (answer.checked) {
        field.value = answer.answer;
        field.value_correct = answer.correct
      } else {
        field.value = null;
      }
    };

    $scope.updateSelection = function(position, entities) {
      angular.forEach(entities, function(answer, index) {
        if (position != index) 
          answer.checked = false;
      });
    }

  });
</script>
<div ng-app="exampleApp">

最后你会看到应用程序的调用位置(我对Angular很新,所以如果我使用错误的术语我提前道歉)。

当模块无法正常工作时,我得到错误:$ injector:nomod 模块不可用错误,包含以下内容......

模块&#39; exampleApp&#39;不可用!您要么错误拼写了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。

0 个答案:

没有答案
相关问题