1

I have created simple directive with a few parameters passed, but my parameters are not passed to Template from Usage code. (they are not displayed on page, no error is displayed too). I also used '@' instead of '=' but there was no real improvement.

I just want to display my attribute parameters in my directive code:). Thanks for help.

Usage code:

<fine-faulty-directive fineCount='111' finePercentage='11' 
faultCount='222' faultPercentage='11'></fine-faulty-directive>

Directive code:

Application.Directives.directive('fineFaultyDirective', function () {
    return {
        restrict: 'E',
        templateUrl: 'src/Dashboard/Views/fine_faulty.html',
        //replace: true,
        scope: {
            fineCount: '=',
            finePercentage: '=',
            fauntCount: '=',
            faultPercentage: '='
        },
        link: function (scope, elem, attrs) {
            console.log(scope);

        }
    };
});

Simple templateURL:

{{faultPercentage}}%  - {{faultCount}}
3
  • do you have something in console.log ? does your template is well loaded ? does your directive is well loaded ? Commented Mar 17, 2015 at 14:26
  • No errors in FF console. Commented Mar 17, 2015 at 14:28
  • In any case you should use the @ instead of the =. That should work fine. Your issue is that you need to define your attributes as fine-count, fine-percentage, etc. Commented Mar 17, 2015 at 14:30

2 Answers 2

3

The attributes fineCount, finePercentage, faultCount, faultPercentage are normalized names (such as directive's name), so if you want to set it to the element, each attribute name must be fine-count, fine-percentage, fault-count, fault-percentage...

I hope I helped.

Sign up to request clarification or add additional context in comments.

Comments

0

Because of

<fine-faulty-directive fineCount='111' finePercentage='11' 
faultCount='222' faultPercentage='11'></fine-faulty-directive>

AngularJS will translate finePercentage to finepercentage and fineCount to finecount

to avoid such circumstances, use fine-percentage instead of finePercentage and fine-count instead of fineCount

NOTE: all attribute which are camel cases in attribute should be separated with - or : so that you can get them camel case in your JS code.

2 Comments

Your answer is wrong because it translates finePercentage to fine-percentage moreover there is already a correct answer written.
AR7, BTW it will not translate on HTML side so on HTML it will be same as finePercentage, it will be translated in JS code i.e attrs of link function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.