我正在玩AngularJS,我写了一小段代码,我已经分享了here。但由于某种原因,数据的绑定不会发生。以下是那些不想访问plucker网站的人的HTML和JS代码。
first.html
<!doctype html>
<html ng-app="firstApp">
<head>
<title>First Angular JS</title>
<script src="/lib/angular.min.js"></script>
<script src="/js/first.js"></script>
</head>
<body>
<div ng-controller="FirstController">
<span>Name:</span>
<input type="text" ng-model="first">
<input type="text" ng-model="last">
<button ng-click='updateMessage()'>Message</button>
<hr>{{heading + message}}
</div>
</body>
</html>
first.js
var firstApp = angular.module('firstApp',[]);
firstApp.controller = ('FirstController',function($scope)
{
$scope.first = "Some";
$scope.last = "one";
$scope.heading = "Message: ";
$scope.updateMessage = function()
{
$scope.message = 'Hello' + $scope.first + ' ' + $scope.last + '!';
};
});
在HTML中,我使用express将调用重定向到适当的位置
node_server.js
var express = require('express');
var app = express();
app.use('/', express.static('./static')).
use('/images',express.static('./images')).
use('/lib',express.static('./lib/angular-1.2.22'));
app.listen(8080);
输出显示{{message + heading}}。有没有人有任何想法为什么这不起作用?
答案 0 :(得分:2)
问题在于你宣布你的控制器。
你有:
firstApp.controller = ('FirstController',function($scope) ...
应该是:
firstApp.controller('FirstController', function($scope) ...
答案 1 :(得分:1)
试试这个:
firstApp.controller('FirstController',['$ scope',function($ scope){...