Wants to use the link function of the directive. Such that it should display a name and on click should change it to the new given name. but there is some error in my template property. w
Where do i get wrong?
JS code-
var app=angular.module("app",[]);
app.controller("myController",function($scope){
});
app.directive("myDirective",function(){
return{
restrict:"EA",
link: function($scope,element,attr){
$scope.name="Hello World";
$scope.changeName=function(newName){
$scope.name=newName;
}
},
template: '<span ng-click="changeName('Hi!')">current name:{{name}}</span>'
};
});
HTML code-
<hmtl>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular.js"></script>
<script src="example4.js"></script>
</head>
<body ng-app="app">
<div ng-controller="myController">
<div my-directive ></div>
</div>
</body>
</hmtl>
Сначала я ограничил директиву "EA".Затем предоставил имя для Scope и функцию "changeName" для области.Затем предоставил шаблон для изменения инициализированного имени на newName при нажатии.