Angular js控制器未注册

时间:2017-03-27 18:45:32

标签: angularjs

我是angularjs和nodejs的新手,我正在做的是创建一个index.html的html文件名,并创建一个controller.js文件,其中打印一个console.log消息,但在控制台框中的浏览器上出错我的代码如下

R.id.editTextTextWidget

<html ng-app>

 <head>
 <title> App </title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

和controller.js代码如下

 <body>
     <div class="container" ng-controller="AppCtrl">
    <h1> Contact List App </h1>
      <table class="table table-bordered">
        <thead>
            <tr>
                <td> name </td>
                <td> Email </td>
                <td> mobile </td>
            </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular.min.js"></script>
<script src="controllers/controller.js"></script>

1 个答案:

答案 0 :(得分:0)

首先,你不能称之为Angular App。

你没有 module 。声明一个模块如下,

 var app = angular.module('todoApp', []);

注册控制器,

app.controller("dobController", ["$scope",
      function($scope) {
}

您尚未提及角度 reference

<强>样本

var app = angular.module('todoApp', []);
app.controller("dobController", ["$scope",
  function($scope) {
    console.log("Hello Bro");
  }
]);
<!DOCTYPE html>
<html ng-app="todoApp">
<head>
  <title>To Do List</title>
  <link href="skeleton.css" rel="stylesheet" />
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
</head>
<body ng-controller="dobController">
  <div class="col-md-20">
   </div>
</body>

</html>