Ish*_*yal 2 html javascript angularjs
我正在尝试构建我的第一个AngularJS应用程序,但它无法正常工作,我无法找到问题,为什么它不起作用.它没有在html页面上显示sayHello函数的名称和结果.
这是我的js和html文件.
(function(){
// body...
'use strict';
angular.module('myFirstApp',[]);
.controller('myFirstController', function($scope){
// body...
$scope.name = "Isha";
$scope.sayHello = function() {
// body...
return "Hello";
}
});
})();Run Code Online (Sandbox Code Playgroud)
<html>
<head>
<title>My First AngularJS App</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<h1>My First AngularJS App</h1>
<div ng-app="myFirstApp" ng-controller="myFirstController">
{{sayHello()}}
{{name}}
</div>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
只需删除; 在模块之后,添加控制器.否则你需要声明为
var app = angular.module('myFirstApp',[]);
Run Code Online (Sandbox Code Playgroud)
然后
app.controller('myFirstController', function($scope){
Run Code Online (Sandbox Code Playgroud)
DEMO
(function(){
// body...
'use strict';
angular.module('myFirstApp',[]).controller('myFirstController', function($scope){
$scope.name = "Isha";
$scope.sayHello = function() {
return "Hello";
}
});
})();Run Code Online (Sandbox Code Playgroud)
<html>
<head>
<title>My First AngularJS App</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<h1>My First AngularJS App</h1>
<div ng-app="myFirstApp" ng-controller="myFirstController">
{{sayHello()}}
{{name}}
</div>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1447 次 |
| 最近记录: |