简体   繁体   English

如何在我的blade.php中为角度$ scope分配值

[英]How to assign value to angular $scope in my blade.php

I get values form laravel View::make('----', $data) . 我从laravel View::make('----', $data)获取值。 And I want to assign some values to the angular $scope.var1 ... , if it cannot assign to $scope . 我想为角度$scope.var1 ...分配一些值,如果它不能分配给$scope Can I assign it to a local javascript var, and use the var in angular app? 我可以将其分配给本地javascript var,然后在angular app中使用var吗?

according Jared Eitnier 's advice, finally I implement as this, server side, public function info() 根据Jared Eitnier的建议,最后我以此为实现,服务器端,公共函数info()

{
    $data['var1'] = $var1;
    $data['var2'] = $var2;
    $data['var3'] = $var3;
    ...
    return Response::json($data);
}

client side, $http.get("url") 客户端$ http.get(“ url”)

.success(function(response)
{
    $scope.var1 = response.var1;
    $scope.var1 = response.var1;
    $scope.var1 = response.var1;
    ...
});

when you start your angular app, use app.value() to store data in app service; 启动角度应用程序时,请使用app.value()将数据存储在应用程序服务中; then get it by dependency injection. 然后通过依赖注入获得它。

example: 例:

<script>
<?php
    $data = View::make('----', $data)
?>
app.init(<?php echo json_encode($data)?>)
/* 
    app.init = function(phpData){
       app.value('data',phpData);
       app.bootstrap();
    }
*/
/* get data by dependency injection */
app.controller('myController',[$scope,$injector,function($scope,$injector){
    $scope.data = $injector.get('data');

}])
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在blade.php 中使用来自外部.js 文件的代码? - How to use code from external .js files in blade.php? 为什么这个 JS 函数不能正确导入到我的blade.php? - Why doesn't this JS function properly import to my blade.php? 如何使用 HTML 元素属性将数据从 Blade.php 文件传递​​到 React 组件? - How to pass data from blade.php file to a react component using HTML element attributes? Laravel-如何“捕获”传递给刀片的 Javascript 变量。php 视图 - Laravel- How to "catch" a variable with Javascript passed to a blade.php view 获取jQuery函数内部blade.php Laravel的返回参数 - Get return parameter of jQuery function inner blade.php Laravel React-Laravel(7.2)组件未显示在刀片中。php - React-Laravel(7.2) Component not showing in blade.php 在一个刀片中组合 2 个不同的脚本后,脚本不起作用。php 文件(laravel) - Script doesn't work after combining 2 different scripts in one blade.php file (laravel) 如何将值和范围分配给两个串联的字符串 - How to assign value and scope to two concatenated string 在Angular JS中,$ scope变量值从$ http赋值 - In Angular JS $scope variable value assign from $http 当我将$ scope分配给另一个变量并更改新变量的监视值时,不会触发Angular $ scope。$ watch - Angular $scope.$watch is not triggered when i assign $scope to another variable and change the watched value on new variable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM