gpt4 book ai didi

javascript - Angular ' as ' 不是一个函数,在错误( native )中未定义

转载 作者:行者123 更新时间:2023-12-03 11:48:01 25 4
gpt4 key购买 nike

我一直在尝试制作一个非常简单的 Angular 应用程序来创建更具视觉吸引力的作品集,但我似乎无法解决此错误。我尝试了很多方法都没有成功,希望你们能帮助我找出错误。提前致谢!

错误:

Error: Argument 'MainController as portfolio' is not a function, got undefined at Error (native)

这是 html 和 js 的代码:

Javascript:

(function() {
var app = angular.module('PortfolioApp',[]);

app.controller('MainController', function(){
this.projects = projects;
});

var projects = [<info>];

})();

HTML:

  <!DOCTYPE html>
<html>
<head>
<title>Luis Lamadrid - Projects</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js" type="text/javascript"></script>
<script src="javascripts/app.js" type="text/javascript"></script>
<link rel="stylesheet" href="stylesheets/app.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>

<div class='container'>
<div class='row-centered'>
<div class='col-lg-8 col-lg-offset-2'>

<div id='content' ng-app=PortfolioApp ng-controller='MainController as portfolio'>
<h1>{{ understand }}</h1>

<div ng-repeat='project in portfolio.projects'>
<h2>
{{ project.name }}
<small> - {{ project.started_date }}</small>
<a href="{{project.link}}" class="no-deco right"><i class="fa fa-github fa-lg"></i></a>
</h2>
<h2>

</h2>
<br>
{{ project.description }}<br><br>
<small>Developed on: <em>{{ project.framework }}</em> </small>
<hr>
</div>

</div>
</div>
</div> <!-- row-centered -->
</div> <!-- container -->


<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</body>
</html>

最佳答案

在你的 Html 中你应该像这样定义 ng-app 。 <html ng-app="AppName">如果可能的话,你应该使用更多版本的 Angular

关于javascript - Angular '<controller> as <variable>' 不是一个函数,在错误( native )中未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25962225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com