how to combine codeigniter and angularjs? -
i've see lot posts codeigniter , angularjs work together,but of them retriving data , pass data .my question more basic.
i run site through php,then every thing ok,means angularjs work properly.but when run through controller,it didn't work.what's wrong?here parts of codes:
<body ng-app="myapp" ng-controller="myctrl"> first name: <input type="text" ng-model="firstname"><br> last name: <input type="text" ng-model="lastname"><br> <br> full name: {{firstname + " " + lastname}}
class first extends ci_controller{ public function index(){ $this->load->view('first'); } }
var app = angular.module('myapp', ['ngmaterial']); app.controller('myctrl', function($scope) { $scope.firstname = "john"; $scope.lastname = "doe"; });
my controller file first.php,view file first.php well.when browse site http://localhost/ci_ngtest/index.php/first, first , last name input blank,and full name show {{firstname + " " + lastname}} instead of john doe
here project structure:
--application --node_modules --angular --angular.js --angular-material --system --user_guide --somefiles(somefiles below)
you need configure script path properly:
- first set
base_url
inside application\config\config.php:
$config['base_url']= 'http://localhost/ci_ngtest/index.php/';
- load library inside application\config\autoload.php
$autoload['helper'] = array('url');
- configure script path:
<script src="<?php echo base_url();?>node_modules/angular/angular.js"></script> <script src="<?php echo base_url();?>node_modules/angular-material/angular-material.js"></script>
Comments
Post a Comment