(Lern AngularJS, Version 1.5.5) AliasingAngularJS 1.5.5 Vorlage nicht bei der Arbeit des Controllers
ich den Code unter
<form ng-submit="addCust.submit()" ng-controller="AddCustomerCtrl as addCust">
<div> <input type="text" ng-model="addCust.cName" required/> </div>
<div> <input type="text" ng-model="addCust.cCity" required/> </div>
<div> <button id="f1" type="submit" >Add Customer</button> </div>
</form>
Die controller.js bekam ist enthält den Code unten
helloWorldControllers.controller('AddCustomerCtrl', ['$scope', '$location',
function AddCustomerCtrl($scope, $location) {
$scope.submit = function(){ console.log('AddCustomerCtrl.submit !');
$location.path('/addedCustomer/' + $scope.cName + "/" + $scope.cCity); };
}
]);
Alles ist in Ordnung, wenn ich die Kontrolle in HTML vermeiden Aliasnamen ("AddCustomerCtrl als addCust")
Ich weiß nicht, wo ich falsch liege. Jede Hilfe ist willkommen. Danke im Voraus !
(... ja, ich bin neu in AngularJS)
Juan
Ich glaube nicht, dass dieser Code funktioniert, da dies die Submit-Funktion referenziert, nicht den Controller, wenn der Code ausgeführt wird. –
@MikeFeltman Es wird gut funktionieren, wie durch [diese einfache JSFiddle] (https://jsfiddle.net/js5y0dxm/) bewiesen. – Lex
Deine Geige zeigt das nicht wirklich, aber ich habe etwas hinzugefügt und es funktioniert. Es wird immer noch nicht empfohlen, dies auf diese Weise zu verwenden. –