-1

here is my module

/// <reference path="angular.js" />
var myModule = angular.module('myModule', ['ngRoute']);

here is my controller in the different js file

angular.module('myModule').controller('myController', function ($scope, customersaveService) {
    $scope.message = '';
    $scope.IsFormValid = false;
    $scope.ButtonText = 'Save';
    $scope.submitted = false;
});

_Layout.cshtml has ng-app set up on the <html ng-app="myModule"></html>

but when i call this from the view

<div ng-controller="myController">
<form name="f1" ng-submit="SaveCustomer(data)" novalidate>
    <span style="color:red">{{message}}</span>
    First name:
    <input  type="text" name="txtFirstName" ng-model="User.FirstName" ng-class="submitted?ng-dirty:''"  required autofocus />
    <span ng-class="error" ng-show="((f1.txtFirstName.$dirty || submitted) && f1.txtFirstName.$error.required)">Please enter a first name</span>
    <br />
    <input type="submit" value={{buttontext}} />
</form>
</div>

when the page loads the chrome console shows the error 'myController' is not a valid function. i could not think of any reason why this throws this error?

here is the error:

angular.js:13236 Error: [ng:areq] Argument 'myController' is not a function, got undefined http://errors.angularjs.org/1.5.0/ng/areq?p0=myController&p1=not%20a%20function%2C%20got%20undefined at angular.js:68 at assertArg (angular.js:1825) at assertArgFn (angular.js:1835) at angular.js:9831 at setupControllers (angular.js:8852) at nodeLinkFn (angular.js:8898) at compositeLinkFn (angular.js:8226) at compositeLinkFn (angular.js:8229) at compositeLinkFn (angular.js:8229) at publicLinkFn (angular.js:8106)(anonymous function) @ angular.js:13236 http://localhost:26210/favicon.ico Failed to load resource: the server responded with a status of 404 (Not Found)

pyykke dasher
  • 41
  • 1
  • 10

1 Answers1

0

Try with this:

myModule.controller('myController', [ "$scope","customersaveService", function ($scope, customersaveService) {
  $scope.message = '';
  $scope.IsFormValid = false;
  $scope.ButtonText = 'Save';
  $scope.submitted = false;
}]);
Mahbubur Rahman
  • 4,961
  • 2
  • 39
  • 46