Po prostu bawię się Angularjs i napisałem mały kawałek kodu, który mam wspólny tutaj . Ale z jakiegoś powodu wiązanie danych nie stało się. Oto kod HTML i JS dla tych, którzy nie chcą iść na stronę Plucker.
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 + '!';
};
});
W HTML używam Express, aby przekierować połączenia do odpowiednich miejsc
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);
Wyjście pokazuje {{Message + Heading}}. Czy ktoś ma jakieś pomysły, dlaczego to nie działało?
1
Rivas
15 sierpień 2014, 03:43
2 odpowiedzi
Najlepsza odpowiedź
Problem polega na tym, jak ogłaszasz kontrolera.
Ty masz:
firstApp.controller = ('FirstController',function($scope) ...
Powinno być:
firstApp.controller('FirstController', function($scope) ...
2
gconsidine
14 sierpień 2014, 23:53
Spróbuj tego:
Firstapp.Controller ("FirstController", ['$ Scope', Funkcja ($ Scope) {...
Doktora dla kontrolera w kątowym
1
betomoretti
15 sierpień 2014, 00:17