Angular JS 1.3.11:参数' MyController'不是功能 [英] Angular JS 1.3.11: Argument 'MyController' is not a function

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

问题描述

我是新来的有角度的人,我有一个问题.

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

我使用的是1.3.11版本的angular.

Im using 1.3.11 version of angular.

我编写了一个简单的html代码,该代码使用简单的angular并收到以下错误:

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代码是:

<!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>

谢谢.

推荐答案

工作中的矮人

<!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>

检查角度模块的定义:

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

而且,模块"app"现在被注入了html

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

<html ng-app="app">

在运行中进行检查此处

这篇关于Angular JS 1.3.11:参数&amp;#39; MyController&amp;#39;不是功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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