0

Briefly: I am trying to pass a string to an angular function on ng-click. The string needs to have embedded data within it from the angular world (the string is composite of a a static fragment and an Angular 'variable')...

<button ng-click="hello('Mr/Ms {{name}}')">Test</button>

Problem: I can't seem to make angular switch back and parse the brackets as anything other than a string. So, how do I fix/reaarange/modify the string so that the embedded Angular content is passed within the string on ng-click.

Desired Outcome On success I should see a javascript alert stating "hello Mr/Ms Samuel"

Plunkr ... http://plnkr.co/edit/vKMCpAjfXbYZtNgxqubv

HTML

<div id="parent" ng-controller="test">
  <p>{{name}}</p>
  <button ng-click="hello('Mr/Ms {{name}}')">Test</button>
</div>

Javascript

$(document).ready(function(){

    var app = angular.module("app",[]);

    app.controller("test",function($scope){
      $scope.name="Samuel";
      $scope.hello=function(val){
        alert("hello " + val);
      };
    });

    angular.bootstrap(document,["app"]);

});
3
  • 2
    ng-click="hello('Mr/Ms '+name)" Commented Feb 18, 2014 at 16:48
  • I knew it would be simple, please post as answer. Commented Feb 18, 2014 at 16:50
  • So, anyone care to elaborate as to why a minus 1 ?? Commented Feb 18, 2014 at 17:03

1 Answer 1

2

just use classic javascript variable, not an angular expression

ng-click="hello('Mr/Ms '+name)"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.