角JS 1.3.11:参数'myController的“不是一个函数 [英] Angular JS 1.3.11: Argument 'MyController' is not a function

查看:202
本文介绍了角JS 1.3.11:参数'myController的“不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我新的角度和我有一个问题。

I'm new to angular and i have a question.

即时通讯使用1.3.11版本的棱角分明。

Im using 1.3.11 version of angular.

香港专业教育学院写了一个简单的HTML code,它是使用简单的角度和即时得到以下错误:

Ive wrote a simple html code that that using simple angular and im getting the following error:

参数myController的'是不是一个功能,AngularJS得到未定义[复制]

Argument 'MyController' is not a function, got undefined in AngularJS [duplicate]

在html code是:

the html code is:

<!DOCTYPE html>
<html ng-app>
<head>
<meta charset="UTF-8">
<title>Angular Demo</title>
<script src="lib/angular/angular.min.js">
 </script>
</head>
<body>

<div ng-controller = "MyController">
  <h1> {{author.name}}</h1>
  <p> {{author.title + ', ' + author.company}}</p>
</div>

<script>
  function MyController($scope)
  {
    $scope.author= {
      'name' : 'Naim',
      'title' : 'MR',
      'company' : 'Naimos'
    }
  }
</script>

</body>
</html>

感谢您提前。

推荐答案

工作plunker

<!DOCTYPE html>
<html ng-app="app">

  <head>
    <meta charset="UTF-8" />
    <title>Angular Demo</title>
    <script data-require="angular.js@*" data-semver="1.3.11" 
     src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.js"
    ></script>
  </head>

  <body>
    <div ng-controller="MyController">
      <h1> {{author.name}}</h1>
      <p> {{author.title + ', ' + author.company}}</p>
    </div>
    <script>
  function MyController($scope)
  {
    $scope.author= {
      'name' : 'Naim',
      'title' : 'MR',
      'company' : 'Naimos'
    }
  }
  angular
    .module('app', [])
    .controller("MyController", MyController)
    </script>
  </body>

</html>

检查角模块的定义:

Check the definition of the angular module:

  angular
    .module('app', [])
    .controller("MyController", MyController)

和也,模块应用程序如今被注入INT HTML

And also, the module "app" is now injected int html

<html ng-app="app">

检查它在行动这里

这篇关于角JS 1.3.11:参数'myController的“不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆