Eduardo
Eduardo

Reputation: 709

KendoUI stops working when separate AngularJS in a .js file

I'm trying to do a simple project with KendoUi + AngularJs.

When I use the code below, it works fine:

<!DOCTYPE html>

<head>
    <title>AngularJS</title>
    <meta charset="utf-8">
    <link href="Content/kendo/2014.2.716/kendo.common.min.css" rel="stylesheet" />
    <link href="Content/kendo/2014.2.716/kendo.rtl.min.css" rel="stylesheet" />
    <link href="Content/kendo/2014.2.716/kendo.default.min.css" rel="stylesheet" />
    <script src="Scripts/kendo/2014.2.716/jquery.min.js"></script>
    <script src="Scripts/kendo/2014.2.716/angular.min.js"></script>
    <script src="Scripts/kendo.all.min.js"></script>


</head>
<body>
    <a class="offline-button" href="../index.html">Back</a>
    <div id="example" ng-app="KendoDemos">
        <div class="demo-section k-content" ng-controller="MyCtrl">
            <div class="box-col">
                <h4>Set Value</h4>
                <p>
                    <input kendo-numeric-text-box k-min="0" k-max="100" k-ng-model="value" />
                </p>
            </div>
            <div class="box-col">
                <h4>Set Value</h4>
                <div kendo-slider k-min="0" k-max="100" k-ng-model="value"></div>
            </div>
            <div class="box-col">
                <h4>Result</h4>
                Value: {{value}}

            </div>
        </div>
    </div>

    <script>
        angular.module("KendoDemos", ["kendo.directives"]);
        function MyCtrl($scope) {
            $scope.value = 50;
        }
</script>
</body>
</html>

But, when I try to separate the angular code into a .js file, (like below), it doesn't work anymore:

<!DOCTYPE html>

<head>
    <title>AngularJS</title>
    <meta charset="utf-8">
    <link href="Content/kendo/2014.2.716/kendo.common.min.css" rel="stylesheet" />
    <link href="Content/kendo/2014.2.716/kendo.rtl.min.css" rel="stylesheet" />
    <link href="Content/kendo/2014.2.716/kendo.default.min.css" rel="stylesheet" />
    <script src="Scripts/kendo/2014.2.716/jquery.min.js"></script>
    <script src="Scripts/kendo/2014.2.716/angular.min.js"></script>
    <script src="Scripts/kendo.all.min.js"></script>
    <script src="Scripts/app/itensApp.js"></script> <!--ADDED-->
</head>
<body>
    <a class="offline-button" href="../index.html">Back</a>
    <div id="example" ng-app="KendoDemos">
        <div class="demo-section k-content" ng-controller="MyCtrl">
            <div class="box-col">
                <h4>Set Value</h4>
                <p>
                    <input kendo-numeric-text-box k-min="0" k-max="100" k-ng-model="value" />
                </p>
            </div>
            <div class="box-col">
                <h4>Set Value</h4>
                <div kendo-slider k-min="0" k-max="100" k-ng-model="value"></div>
            </div>
            <div class="box-col">
                <h4>Result</h4>
                Value: {{value}}

            </div>
        </div>
    </div>
</body>
</html>

Scripts/itensApp.js

(function() {
    var itensApp = angular.module('KendoDemos', ["kendo.directives"]);
}());

What I'm doing wrong?

Regards

Upvotes: 0

Views: 239

Answers (1)

yccteam
yccteam

Reputation: 2311

It seems that you did not add the controller to your file.

Here's the code for the external .js file:

angular.module("MyApp", ["kendo.directives"]);
function MyCtrl($scope) {
    $scope.value = 50;
}

Here's a working example: http://plnkr.co/edit/3vRqvvvQZ8w6RRVohVdi?p=preview

Upvotes: 1

Related Questions