1

Why this custom directive in angular js not working for me.I am only getting the user: but not getting the names of the user which I passed in the userinfo custom directive tag

user_directive_index.html file:

<html ng-app='app' >
<head>
</head>
<title>
User Directive
</title>
<body >

<div>
<div ng-model='firstcontroller'>
<userinfo user="Raj"></userinfo>
</br>
<userinfo user="Sudhir"></userinfo>
</div>
</div>
<script type="text/javascript" src="../js/angular.min.js"></script>
<script src='app.js'></script>
</body>
</html>

App.js file:

var app1=angular.module('app',[]);
app1.controller('firstcontroller',function($scope){
$scope.Raj={};
$scope.Raj.firstname='Rajeshwar';
$scope.Raj.lastname='Bose';
$scope.Sudhir={};
$scope.Sudhir.firstname='Sudhir';
$scope.Sudhir.lastname='Ranjan';

});

app1.directive('userinfo',function(){
var directive={};

directive.restrict='E';
directive.template='User:{{user.firstname}} {{user.lastname}}';

directive.scope={
user:"= user"
};

return directive;
});

I got this code from: http://tutorials.jenkov.com/angularjs/custom-directives.html

0

1 Answer 1

1

You have to change directive ngModel here

<div ng-model='firstcontroller'>
        ^^^^^

To ngController

<div ng-controller='firstcontroller'>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot dude....can I have your email id..so that I can put my doubts directly over there.You seem to be lot experienced in this framework.And I am really in urgent need of some guide to help me out in Angular JS.
@Rajeshwar If this answer helps you and it solved your problem, please consider accepting the answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.