I have this directive, where I'm trying to get some news via HTTP GET method, based on some options
import publicListTpl from './public-list.html';
(() => {
angular
.module('news.crud.directives', [])
.directive('newsPortalPublishedList', () => ({
restrict: 'E',
replace: true,
templateUrl: publicListTpl,
scope: {
type: '@'
},
controller: ($scope, $http, FlashMessages) => {
$http.get('/api/portal/'+$scope.type)
.then(response => $scope.news = response.data)
.catch(() => FlashMessages.add(FlashMessages.ERROR, 'La récupération des '+$scope.type+' a échoué.'));
}
})); })();
The problem that when I add the scope
option scope: {type: '@'}
, I cant access to any defined route into my publicListTpl
template, for example url('news_edit', {id: news.id})
will return null
.
This is my html template:
<div class="portlet" ng-repeat="news in newsList">
<div class="portlet light bordered">
<div class="portlet-title">
<div class="caption">
{{ news.title }}
<small>{{ news.subtitle }}</small>
</div>
<div class="actions">
<a class="btn btn-info btn-sm" href="{{ url('news_edit', {id: news.id}) }}">
<i class="fa fa-pencil"></i> Editer
</a>
</div>
</div>
<div class="portlet-body">
<img ng-if="news.image" src="{{ news.image }}" class="pull-left" height="100"/>
<div ng-bind-html="news.shortContent"></div>
</div>
</div>
</div>
Ps: I don't even know the source problem, so you can edit the question to make it more clear.