TheBoubou
TheBoubou

Reputation: 19933

Error when assign controller to div

With the code below, I see my button (angular 1.3.15, DevExtreme 15.1.4)

HTML :

<!DOCTYPE html>
<html ng-app="myApp">
<head>
    <meta charset="utf-8">
    <title>Testing</title>    
    <link href="Content/dx.common.css" rel="stylesheet" />
    <link href="Content/dx.light.css" rel="stylesheet" />    
</head>
<body>    
    <script src="/Scripts/jquery-1.11.3.min.js"></script>
    <script src="/Scripts/jquery.globalize/globalize.js"></script>    
    <script src="/Scripts/angular.min.js"></script>
    <script src="/Scripts/angular-sanitize.min.js"></script>
    <script src="/Scripts/angular-ui-router.min.js"></script>    
    <script src="/Scripts/dx.webappjs.js"></script>    
    <script src="/app/app.js"></script>    

    <div ng-controller="myCtrl">
        <div dx-button="{text: 'Test Button'}"></div>
    </div>    

</body>
</html>

app.js file :

var myApp = angular.module('myApp', ['dx']);

(function () {
    angular.module('myApp')
        .controller('myCtrl', ['$scope','dx', myCtrl]);

    function myCtrl($scope, dx) {
        var vm = this;
    }
}());

I see the button and no error but when I add the controller in the div :

<div ng-controller="myCtrl">
    <div dx-button="{text: 'Test Button'}"></div>
</div>

I get this error : Error: [$injector:unpr] http://errors.angularjs.org/1.3.15/$injector/unpr?p0=dxProvider%20%3C-%20dx%20%3C-%20myCtrl R/<@http://localhost:51314/Scripts/angular.min.js:6:417

Upvotes: 0

Views: 115

Answers (1)

sdgluck
sdgluck

Reputation: 27327

You are attempting to inject the dx module into your myCtrl controller. Try removing it:

var myApp = angular.module('myApp', ['dx']);

(function () {
    angular.module('myApp')
        .controller('myCtrl', ['$scope', myCtrl]);

    function myCtrl($scope) {
        var vm = this;
    }
}());

For future reference, following the link given in an Angular error can help reveal problems like these.

Upvotes: -1

Related Questions