How Can I Check Ng-if Value With One Php Value
Solution 1:
Its not a good way of doing that. If you want to do, then simply fire an AJAX call and set your value
in controller scope's object. But if you want to do it in this way then you can achieve it by using ng-init
directive, like I've done in one of my projects. Just use
<divdata-ng-app="MyApp"data-ng-controller="DemoController"data-ng-init="value='<?phpecho$value?>'">
and in your condition, use like
<div data-ng-if="val.PRDCODE == value">
Hope it may help you.
Solution 2:
If you have problems in getting values on the webpage. You can simple call a function and return true/false which can be evaluated on the page.
e.g
<divng-if="myCondition()"></div>
Solution 3:
This is not a great approach and also has a risk to expose your private data in the source code. But If you dont care about your data to be exposed then you can;
<head><script>
angular.module("NAME OF YOUR APP")
.controller("name___ctrl", function($scope){
$scope.phpValue = '<?php$value; ?>'
});
</script></head><bodyng-controller="name___ctrl">
{{phpValue}}
</body>
Another way is to use ng-init
<divng-controller="FooCtrl"><spanng-init="phpValue= true">something</span></div>
This would be the healthiest overall..
An Angular way of getting data in, is to use services/factories. Basically make an http call to a json responding endpoint and fetch the data.
//Make sure to make your $http calls inside your Factories or Services. This is just for a testing purpose.
.controller(function($http){
$http.get("api/endpoint")
.then(function(success)
{
phpValue = success.data
},
function(error)
{
console.log("oops something went really wrong")
})
})
once you got phpdata just use it as you wish
<divng-controller="FooCtrl"><spanng-if="someValue == phpValue">something</span></div>
Post a Comment for "How Can I Check Ng-if Value With One Php Value"