Angular Controller 无法与index.html连接,该项目使用安装了node.js的http服务器运行。
classifieds.js
`(function() {
"use strict";
angular
.module("ngClassifieds")
.controller("ClassifiedsCtrl", ['$scope', function($scope) {
$scope.name ={text: 'Asif'};
};
}]();`
index.html
`<!DOCTYPE html>
<html>
<head>
<title>ngClassifieds</title>
</head>
<body ng-app="ngClassfieds" ng-controller="ClassifiedsCtrl">
<input type="text" placeholder="Whats your name" ng-model="name" >
<h1>{{greeting.text}}</h1>
<script src="node_modules/angular/angular.min.js"> </script>
<script src="scripts/app.js"></script>
<script src="components/classifieds.js"></script>
</body>
</html>`
最佳答案
您的classified.js 文件应如下所示
angular.module("ngClassifieds",[])
//you should pass an empty array in every module NOTE:inside the array it can the injected field
(function() {
"use strict";
.controller("ClassifiedsCtrl", ['$scope', function($scope) {
$scope.name ={text: 'Asif'};
};
}]();
关于javascript - 无法运行 angularjs 文件 Controller 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38092852/