0

I have this view in AngularJS:

<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 type="submit">Add Customer</button>
</div>

And my controller is:

helloWorldControllers.controller('AddCustomerCtrl',['$scope','$location',
function AddCustomerCtrl($scope, $location){
    $scope.submit = function(){
        $location.path('/addedCustomer/' + $scope.cName + "/" + $scope.cCity);
    };
}
]);

But the "as" operator doesn't work in my netbeans.

My goal is to attach multiple controllers to one element, so I don't want to change the name of controller in itself, but as needed in the view where I want to attach controller to the element. Can anyone please help me where it is wrong? Thanks a lot.

0

1 Answer 1

2

Modify your controller as:

helloWorldControllers.controller('AddCustomerCtrl',['$location', function AddCustomerCtrl($location){ 
  var addCust = this;
  addCust.submit = function(){ $location.path('/addedCustomer/' + addCust.cName + "/" + addCust.cCity); }; } ]); 
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, your answer is right, but my goal is to attach multiple controllers to one element, so I don't want to change the name of controller in itself, but as needed in the view where I want to attach controller to the element.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.