user1494625 user1494625 - 3 years ago 186
HTML Question

Angular JS 1.5 Component html content shown as commented out in browser

I am new to the Angular world, and while trying out a few things, I am basically stuck with a basic angular component problem.

So the idea is to simply add a custom element called "cast-tile" to the page which would be loaded by angular as a component. But the browser somehow shows the code in ng-repeat as commented.

My code is below


<!DOCTYPE html>
<html ng-app="myApp">

<script data-require="angular.js@1.6.1" data-semver="1.6.1" src=""></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>

<body ng-controller="myCtrl">
<h1>My Favourite X-Men's</h1>

<sample-component data="Jack"></sample-component> <!-- this works -->

<cast-tile cast="mutants"></cast-tile> <!-- does not work -->




var myApp = angular.module('myApp', []);
myApp.controller('myCtrl', function($scope) {
$scope.mutants = [{
name: 'Wolverine',
actor: 'Hujh Jackman',
image: ''
name: 'Cyclops',
actor: 'James Marsden',
image: ''
name: 'Storm',
actor: 'Hally Barry',
image: ''

myApp.component("castTile", {
templateUrl: "myTemplate.html",
bindings: {
cast: '='
restrict: 'E',
controller: function(){


myApp.component("sampleComponent", {
template: '<h3>Hello {{ $ }}</h3>',
bindings: {
data: '@'
restrict: 'AE'

and finally, myTemplate.html

<div class="tiles" ng-repeat="mutant in mutants">
<h3>{{ }}</h3>
<p>{{ }}</p>
<img width="100" height="150" ng-src="{{ mutant.image }}" />

The browser console does not show any errors.

Please find the code on Plunker

Any help is greatly appreciated!

Answer Source

Well, the binding that contains mutants list is called cast in your component castTile. Also, you need to prefix cast with $ctrl., as you correctly did it in sampleComponent:

<div class="tiles" ng-repeat="mutant in $ctrl.cast">

should work ;-)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download