angular controller无法与index.html连接,项目与安装了node.js的http-server一起运行。
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>`
答案 0 :(得分:0)
您的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'};
};
}]();