0

My goal is to declare a static list of objects with some attributes and then map that list onto a <ul> list.

I've got the 'hello-world' component from a tutorial working, but the game-search tag doesn't print anything out.

Here's my code so far:

<html>
<head>
    <title>Slots</title>
    
    <script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
    <script type = "text/javascript">
    var app = angular.module("slots", []);
    

    
    app.component("helloWorld",{
        template: 'Hello -  {{$ctrl.name}}', 
        bindings: {name: '@' }
    });
    
    app.component("gameSearch", {
        controller: function() {
            var ctrl = this;
            alert("controller function");
            this.$onInit = function() {
                alert("On Init");
                ctrl.gameData = [];
            };
            
            
        },
    });
    
    app.run(function() {
        
    })
    </script>
</head>
<body>

<div ng-app="slots"> 
    <hello-world name = "John"> </hello-world>
    
    <game-search>
        {{gameData.length}}
    </game-search>
</div>



</body>
</html>

1 Answer 1

1

You need a template for your component. (And you have to bind it to your controller with bindToController: true and controllerAs: 'gameSearch' if you don't want to use $scope)

<html>
<head>
    <title>Slots</title>
    
    <script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
    <script type = "text/javascript">
    var app = angular.module("slots", []);
    

    
    app.component("helloWorld",{
        template: 'Hello -  {{$ctrl.name}}', 
        bindings: {name: '@' }
    });
    
    app.component("gameSearch", {
        bindToController: true,
        controllerAs: 'gameSearch',
        controller: function() {
            var ctrl = this;            
            this.$onInit = function() {                
                ctrl.gameData = [];
            };
        },
        template:'{{gameSearch.gameData.length}}'
    });
    
    app.run(function() {
        
    })
    </script>
</head>
<body>

<div ng-app="slots"> 
    <hello-world name = "John"> </hello-world>
    
    <game-search></game-search>
</div>



</body>
</html>

Sign up to request clarification or add additional context in comments.

Comments

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.