Javascript 使用ngInit定义变量的角度JS
基本上,我将一个变量从PHP发送到Angular JS。我将PHP变量回送到ng init标记中,并正确呈现(ng init=“listing=5;user=59”)Javascript 使用ngInit定义变量的角度JS,javascript,php,angularjs,Javascript,Php,Angularjs,基本上,我将一个变量从PHP发送到Angular JS。我将PHP变量回送到ng init标记中,并正确呈现(ng init=“listing=5;user=59”) 在ng init之前调用控制器的构造函数。仔细想想,控制器的$scope必须存在,才能ng init向其添加内容 如果将$watch添加到控制器作用域的属性中,如果所有设置都正确,则应看到它发生了更改: function galleryController ($scope, $http, $log) { $scope.$
在ng init
之前调用控制器的构造函数。仔细想想,控制器的$scope
必须存在,才能ng init
向其添加内容
如果将$watch
添加到控制器作用域的属性中,如果所有设置都正确,则应看到它发生了更改:
function galleryController ($scope, $http, $log) {
$scope.$watch('listing', function(value) { console.log(value); });
$scope.$watch('user', function(value) { console.log(value); });
var postData = { listing : $scope.listing, user: $scope.user };
var galleryApp = angular.module('galleryApp', []);
function galleryController ($scope, $http, $log) {
console.log($scope.listing); // <-- undefined
console.log($scope.user); // <-- undefined
var postData = { listing : $scope.listing, user: $scope.user };
function galleryController ($scope, $http, $log) {
$scope.$watch('listing', function(value) { console.log(value); });
$scope.$watch('user', function(value) { console.log(value); });
var postData = { listing : $scope.listing, user: $scope.user };