【问题标题】:Cant connect the module and controller file to index.html无法将模块和控制器文件连接到 index.html
【发布时间】:2018-05-13 07:17:52
【问题描述】:

我是 Angular 的新手,并且有非常基础的知识。最近,在实现基本模块和控件时,我一直遇到同样的问题。我试过关注 youtube 视频,但不知道我做错了什么。

HTML

    <!DOCTYPE html>
      <html ng-app="module">
        <head>
          <title>Angular App</title>
          <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
         <script src="connect.js"></script>
         </head>
         <body ng-controller="control">
               {{message}}
         </body>
         </html>

角度连接.js

    var app= angular.module("module",[]);
     var control= function($scope){
             $scope.message="Hello world!";
        }
     app.controller("control",control);

【问题讨论】:

  • 我在下面给出了答案,如果你愿意,你可以根据需要将 script.js 更改为 connect.js。谢谢。

标签: javascript angularjs module controls


【解决方案1】:

如果脚本名称是Connect.js。修改脚本标签

<script src="Connect.js"></script>

【讨论】:

    【解决方案2】:

    HTML

     <!DOCTYPE html>
          <html ng-app="module">
            <head>
              <title>Angular App</title>
              <script data-require="angular.js@*" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
             <script src="script.js"></script>
             </head>
             <body ng-controller="control">
                   {{message}}
             </body>
             </html>
    

    Angular 脚本.js

    var app = angular.module('module', []);
    app.controller('control', function($scope) {
        $scope.message = "Hello Word!!";
      });
    

    您可以使用以下链接:https://plnkr.co/edit/VhW9BrZ8ukUZecCHkONp?p=preview

    【讨论】:

    • 非常感谢!
    • 没问题,欢迎!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-30
    • 1970-01-01
    • 1970-01-01
    • 2017-09-28
    • 2021-05-22
    • 1970-01-01
    • 2015-10-27
    相关资源
    最近更新 更多