Currently, I am working with Symfony and AngularJs 1.6.8 along with Symfony 3.4. Below is the configuration setup that I have:
base.html.twig
<html lang="en" data-ng-app="CeocApp" ng-controller="CeocController">
//css for the app
<link id="ng_load_plugins_before"/>
//more ccs for the app
<body>
....
<div class="row" ui-view></div>
....
<script src="{{ asset('assets/angular/angular/angular.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('assets/angular/angular-sanitize/angular-sanitize.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('assets/angular/angular-touch/angular-touch.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('assets/angular/angular-ui-router/release/angular-ui-router.min.js') }}"
type="text/javascript"></script>
<script src="{{ asset('assets/angular/oclazyload/dist/ocLazyLoad.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('assets/angular/angular-ui-bootstrap/dist/ui-bootstrap-tpls.js') }}"
type="text/javascript"></script>
<script src="{{ asset('assets/ceoc/angular_app/ceoc-angular-app.js') }}"></script>
</body>
</html>
ceoc-app.js
var CeocApp = angular.module('CeocApp', [
'ui.router',
"ui.bootstrap",
"oc.lazyLoad",
"ngSanitize"
]).config(['$interpolateProvider', function ($interpolateProvider) {
$interpolateProvider.startSymbol('{[{').endSymbol('}]}');
}]);
CeocApp.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/dashboard");
$stateProvider
.state('dashboard', {
url: "/dashboard",
templateUrl: "../templates/dashboard.html",
controller: "DashboardController as dashboard",
resolve: {
deps: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load({
name: 'CeocApp',
insertBefore: '#ng_load_plugins_before',
files: [
'../assets/ceoc/angular_app/controllers/dashboard-controller.js'
]
});
}]
}
})
}]);
Among other things, there are two problems encountered in the controller named `dashboard-controller.js`.
Problem 1:The usage of `$http.get(Rountin.generate('route_name'))` fails to work properly.
Upon running the application, everything functions correctly until reaching the mentioned `$http.get()` request.
angular.module('CeocApp').controller('DashboardController', ['$scope', '$rootScope', function ($scope, $rootScope, $http) {
$rootScope.pageTitle = 'Dashboard';
$scope.total = 2500;
alert('this line will be reached');
$http.get(Routing.generate('ceoc.dashboard')).then(function (data) {
$scope.total = 10000
}, function (data) {
});
alert('this line will never be reached');
}]);
Problem 2: The inability to modify the `$scope` value using `$.get` method.
Although switching to `$.get()` solves the issue of making the AJAX request successfully, it does not allow the modification of `$scope.total` value.
angular.module('CeocApp').controller('DashboardController', ['$scope', '$rootScope', function ($scope, $rootScope, $http) {
$rootScope.pageTitle = 'Dashboard';
$scope.total = 2500;
$.get(Routing.generate('ceoc.dashboard')).success(function (data) {
alert('request successfull');
$scope.total = 200; //this value won't be setted
}).then(function () {
$scope.total = 6000;
});
$scope.total = '879';//this value will be setted
}]);
The provided server response
{"retrasadas":5,"total":10,"en_tiempo":5}
Thus, the main query regarding appropriately setting a `$scope.anyvar` value post a successful AJAX request remains. Does anyone recognize where the flaw lies?
I appreciate your assistance in advance.