angularjs - Angular - when calling a function from ng-show and passing a parameter into it - the parameter becomes undefined -
i having problem angular when call function ng-show hide/show element parameter pass undefined function.
i don't know if it's because using php print html highly doubt it. there no other option me use it.
what possible reason why undefined?
<div ng-app="app"> <div ng-controller="myctrl"> ... <?php ... echo '<li ng-show="toggle(' .$type . ')"></li>' //$type not undefined ... ?> ... </div> </div>
js:
app.controller('myctrl', function($scope) { $scope.toggle = function(type){ console.log(type); //undefined ... } });
i can provide more info if needed.
if goal pass literal string toggle function, forgot add quotes around $type:
echo '<li ng-show="toggle(\'' .$type . '\')"></li>'
so, if php variable $type
has value 'hello', generated html code be
<li ng-show="toggle('hello')"></li>
without quoted, generated html code
<li ng-show="toggle(hello)"></li>
which means javascript function called $scope.hello
argument, undefined.
Comments
Post a Comment