1

I am trying to use an AngularJS $scope as an HTML attribute rather than viewable text.

main.js

var myApp = angular.module('myApp');

myApp.controller("buttonCtrl", ['$scope', function($scope){

$scope.johnny = [
    {quote: 'Anything for My Princess', controller: 'Princess'}
];

}]);

page1.html

<button ng-repeat="button in johnny" 
    ng-class="dynamic" 
    class="topcoat-button"
    ng-controller="{{button.controller}}"   <---- this is what does not work 
    ng-click="play()">
    {{button.quote}}
</button>

How can I fix this so I can add these variables as an attribute value.

Thanks

1

1 Answer 1

1

Angular.js is a bit weird when doing this, but this should work. Also you're using ng-repeat wrong, but it's fixed below.

<button ng-repeat="johnny in buttons" 
    ng-class="dynamic" 
    class="topcoat-button"
    ng-controller="this.johnny.controller"
    ng-click="play()">
    {{johnny.quote}}
</button>
Sign up to request clarification or add additional context in comments.

3 Comments

Hi, Thank you for responding. when I put in this.johnny.controller the button I see {{johnny.quote}} instead of the value. Also, I can only see the buttons if johnny is after "in".
Ah yes, it is buttons in johnny, but I need to use {{button.quote}}; however, ng-controller is not working. I have updated my question so it is correct.
Ohh, I took out the quotes on Princess and that solved it. Thank you very much for leading me to the answer!

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.