Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

controller:ctrlfmt Badly formed controller string ''. Must match `__name__ as __id__` or `__name__`

Tags:

angularjs

In rootes.js

.state('main.mydata', {
    url: '/my-data',
    templateUrl: '/app/views/pages/my-data.html',
    controller: 'mydataCtrl'
})

Controller

.controller('mydataCtrl', ['$scope', '$state', '$http', function($scope, $state, $http) {
    console.log("Came to My Data")
}])

when i call the page getting error in console

Error: angular.js?bundleVirtualPath=~%2fbundles%2fangular:13708 [$controller:ctrlfmt] Badly formed controller string ''. Must match `__name__ as __id__` or `__name__`.
http://errors.angularjs.org/1.5.7/$controller/ctrlfmt?p0=
    at http://localhost:25282/Scripts/angular.js?bundleVirtualPath=%7eNaNbundles%fangular:68:12
    at $controller (http://localhost:25282/Scripts/angular.js?bundleVirtualPath=%7e%fbundles%fangular:10199:17)
    at setupControllers (http://localhost:25282/Scripts/angular.js?bundleVirtualPath=%7e%fbundles%fangular:9331:34)
    at nodeLinkFn (http://localhost:25282/Scripts/angular.js?bundleVirtualPath=%7e%fbundles%fangular:9116:32)
    at compositeLinkFn (http://localhost:25282/Scripts/angular.js?bundleVirtualPath=%7e%fbundles%fangular:8510:13)
    at nodeLinkFn (http://localhost:25282/Scripts/angular.js?bundleVirtualPath=%7e%fbundles%fangular:9210:24)
    at compositeLinkFn (http://localhost:25282/Scripts/angular.js?bundleVirtualPath=%7e%fbundles%fangular:8510:13)
    at compositeLinkFn (http://localhost:25282/Scripts/angular.js?bundleVirtualPath=%7e%fbundles%fangular:8513:13)
    at compositeLinkFn (http://localhost:25282/Scripts/angular.js?bundleVirtualPath=%7e%fbundles%fangular:8513:13)
    at publicLinkFn (http://localhost:25282/Scripts/angular.js?bundleVirtualPath=%7e%fbundles%fangular:8390:30)

What may be the issue?

like image 641
Krishna shidnekoppa Avatar asked Sep 22 '16 07:09

Krishna shidnekoppa


2 Answers

in page

my-data.html

There was div with empty controller name

<div ng-controller="">
  ..
</div>

because of this it was showing

Badly formed controller

like image 64
Krishna shidnekoppa Avatar answered Sep 22 '22 14:09

Krishna shidnekoppa


I just encountered the same problem when calling $mdDialog using angular-material. My issue was that the string referencing my controller had a rogue space at the end. Double check that the string value of your controller key in the .state function object doesn't have any spaces.

Hope this helps anyone else seeing this error as well.

like image 21
Zofskeez Avatar answered Sep 23 '22 14:09

Zofskeez