Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble creating AngularJS directive

I am a first time angularjs user and I am trying to create a directive but I cannot get around this error:

Error: Unknown provider: $scopeProvider <- $scope <- someDirectiveDirective createInjector/providerInjector<@http://localhost:4242/js/lib/angular/angular.js:2734 getService@http://localhost:4242/js/lib/angular/angular.js:2862 createInjector/instanceCache.$injector<@http://localhost:4242/js/lib/angular/angular.js:2739 getService@http://localhost:4242/js/lib/angular/angular.js:2862 ... ... ...

I create my angular app as follows:

var app = angular.module(
  "myApp", 
  ...

I then try and create my directive in another file:

app.directive('someDirective', function($http, $scope, $element, $attrs) {
  return {
    restrict: "A",

Then I use the directive:

I am sure that I am doing something really dumb but I have no idea.

like image 806
lostintranslation Avatar asked Apr 13 '26 12:04

lostintranslation


1 Answers

Try this:

app.directive('someDirective', function($http) {
  return {
    restrict: 'A',
    link: function(scope, element, attrs) {

    }
  };
});
like image 174
EpokK Avatar answered Apr 15 '26 00:04

EpokK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!